type Statistics,
StorageType
} from '../../types/index.js'
-import { logger, setDefaultErrorParams } from '../../utils/index.js'
+import { logger } from '../../utils/index.js'
export abstract class Storage {
protected readonly storageUri: URL
consoleOut: false
}
): void {
- params = setDefaultErrorParams(params, { throwError: false, consoleOut: false })
+ params = {
+ ...{
+ throwError: false,
+ consoleOut: false
+ },
+ ...params
+ }
const inTableOrCollectionStr = table != null && ` in table or collection '${table}'`
logger.error(
`${this.logPrefix} ${this.getDBNameFromStorageType(type)} error '${
const moduleName = 'ErrorUtils'
-const defaultErrorParams = {
- throwError: true,
- consoleOut: false
-} satisfies HandleErrorParams<EmptyObject>
-
export const handleUncaughtException = (): void => {
process.on('uncaughtException', (error: Error) => {
console.error(chalk.red('Uncaught exception: '), error)
fileType: FileType,
error: NodeJS.ErrnoException,
logPrefix: string,
- params: HandleErrorParams<EmptyObject> = defaultErrorParams
+ params?: HandleErrorParams<EmptyObject>
): void => {
- params = setDefaultErrorParams(params)
+ params = {
+ ...{
+ throwError: true,
+ consoleOut: false
+ },
+ ...params
+ }
const prefix = isNotEmptyString(logPrefix) ? `${logPrefix} ` : ''
let logMsg: string
switch (error.code) {
commandName: RequestCommand | IncomingRequestCommand,
messageType: MessageType,
error: Error,
- params: HandleErrorParams<EmptyObject> = {
- throwError: false,
- consoleOut: false
- }
+ params?: HandleErrorParams<EmptyObject>
): void => {
- params = setDefaultErrorParams(params, { throwError: false, consoleOut: false })
+ params = {
+ ...{
+ throwError: false,
+ consoleOut: false
+ },
+ ...params
+ }
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleSendMessageError: Send ${getMessageTypeString(messageType)} command '${commandName}' error:`,
error
chargingStation: ChargingStation,
commandName: IncomingRequestCommand,
error: Error,
- params: HandleErrorParams<T> = { throwError: true, consoleOut: false }
+ params?: HandleErrorParams<T>
): T | undefined => {
- params = setDefaultErrorParams(params)
+ params = {
+ ...{
+ throwError: true,
+ consoleOut: false
+ },
+ ...params
+ }
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
error
return params.errorResponse
}
}
-
-export const setDefaultErrorParams = <T extends JsonType>(
- params: HandleErrorParams<T>,
- defaultParams: HandleErrorParams<T> = defaultErrorParams
-): HandleErrorParams<T> => {
- return { ...defaultParams, ...params }
-}
import {
handleFileException,
handleIncomingRequestError,
- handleSendMessageError,
- setDefaultErrorParams
+ handleSendMessageError
} from '../../src/utils/ErrorUtils.js'
import { logger } from '../../src/utils/Logger.js'
expect(chargingStation.logPrefix.mock.calls.length).toBe(3)
expect(logger.error.mock.calls.length).toBe(3)
})
-
- await it('Verify setDefaultErrorParams()', () => {
- expect(setDefaultErrorParams({})).toStrictEqual({ throwError: true, consoleOut: false })
- expect(setDefaultErrorParams({ throwError: false })).toStrictEqual({
- throwError: false,
- consoleOut: false
- })
- expect(setDefaultErrorParams({ throwError: false, consoleOut: true })).toStrictEqual({
- throwError: false,
- consoleOut: true
- })
- expect(setDefaultErrorParams({ throwError: true, consoleOut: true })).toStrictEqual({
- throwError: true,
- consoleOut: true
- })
- expect(setDefaultErrorParams({}, { throwError: false, consoleOut: false })).toStrictEqual({
- throwError: false,
- consoleOut: false
- })
- })
})