handleFileException(
this.configurationFile,
FileType.ChargingStationConfiguration,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix()
)
if (
handleFileException(
this.templateFile,
FileType.ChargingStationTemplate,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix()
)
}
let requestCommandName: IncomingRequestCommand | RequestCommand | undefined
let errorCallback: ErrorCallback
const [, messageId] = request
+ const ocppError =
+ error instanceof OCPPError
+ ? error
+ : new OCPPError(
+ ErrorType.INTERNAL_ERROR,
+ error instanceof Error ? error.message : String(error)
+ )
switch (messageType) {
case MessageType.CALL_ERROR_MESSAGE:
case MessageType.CALL_RESULT_MESSAGE:
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
;[, errorCallback, requestCommandName] = this.getCachedRequest(messageType, messageId)!
// Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op)
- errorCallback(error as OCPPError, false)
+ errorCallback(ocppError, false)
} else {
// Remove the request from the cache in case of error at response handling
this.requests.delete(messageId)
case MessageType.CALL_MESSAGE:
;[, , commandName] = request as IncomingRequest
// Send error
- await this.ocppRequestService.sendError(this, messageId, error as OCPPError, commandName)
+ await this.ocppRequestService.sendError(this, messageId, ocppError, commandName)
break
}
if (!(error instanceof OCPPError)) {
handleFileException(
this.configurationFile,
FileType.ChargingStationConfiguration,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix()
)
})
handleFileException(
this.configurationFile,
FileType.ChargingStationConfiguration,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix()
)
}
parentPort?.postMessage({
data: {
event,
- message: (error as Error).message,
- name: (error as Error).name,
- stack: (error as Error).stack,
+ message: error instanceof Error ? error.message : String(error),
+ name: error instanceof Error ? error.name : 'UnknownError',
+ stack: error instanceof Error ? error.stack : undefined,
},
event: WorkerMessageEvents.workerElementError,
uuid,
handleFileException(
file,
FileType.Authorization,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix(file)
)
}
handleFileException(
file,
FileType.Authorization,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix(file),
{
throwError: false,
import type { ChargingStation } from '../ChargingStation.js'
-import { BaseError, type OCPPError } from '../../exception/index.js'
+import { BaseError, OCPPError } from '../../exception/index.js'
import {
AuthorizationStatus,
type AuthorizeRequest,
)
responsePayload = {
command,
- errorDetails: (error as OCPPError).details,
- errorMessage: (error as OCPPError).message,
- errorStack: (error as OCPPError).stack,
+ errorDetails: error instanceof OCPPError ? error.details : undefined,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorStack: error instanceof Error ? error.stack : undefined,
hashId: this.chargingStation.stationInfo?.hashId,
requestPayload,
status: ResponseStatus.FAILURE,
return handleIncomingRequestError<GenericResponse>(
chargingStation,
OCPP16IncomingRequestCommand.CANCEL_RESERVATION,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
{
errorResponse: OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_REJECTED,
}
return handleIncomingRequestError<OCPP16DataTransferResponse>(
chargingStation,
OCPP16IncomingRequestCommand.DATA_TRANSFER,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
{ errorResponse: OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED }
)!
}
return handleIncomingRequestError<GetDiagnosticsResponse>(
chargingStation,
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
{ errorResponse: OCPP16Constants.OCPP_RESPONSE_EMPTY }
)!
}
return handleIncomingRequestError<OCPP16ReserveNowResponse>(
chargingStation,
OCPP16IncomingRequestCommand.RESERVE_NOW,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
{ errorResponse: OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED }
)!
}
}
} catch (error) {
return {
- error: `Failed to store certificate: ${(error as Error).message}`,
+ error: `Failed to store certificate: ${error instanceof Error ? error.message : String(error)}`,
success: false,
}
}
chargingStation,
commandName,
MessageType.CALL_ERROR_MESSAGE,
- error as Error
+ error instanceof Error ? error : new Error(String(error))
)
return null
}
chargingStation,
commandName,
MessageType.CALL_RESULT_MESSAGE,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
{
throwError: true,
}
chargingStation,
commandName,
MessageType.CALL_MESSAGE,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
{
throwError: params.throwError,
}
timestamp: result.timestamp,
}
} catch (error) {
- lastError = error as Error
+ lastError = error instanceof Error ? error : new Error(String(error))
logger.debug(
- `${this.chargingStation.logPrefix()} Strategy '${strategyName}' failed: ${(error as Error).message}`
+ `${this.chargingStation.logPrefix()} Strategy '${strategyName}' failed: ${error instanceof Error ? error.message : String(error)}`
)
// Continue to next strategy unless it's a critical error
- if (this.isCriticalError(error as Error)) {
+ if (this.isCriticalError(error instanceof Error ? error : new Error(String(error)))) {
break
}
}
} catch (error) {
const duration = Date.now() - startTime
logger.error(
- `${this.chargingStation.logPrefix()} Direct authentication with ${strategyName} failed (${String(duration)}ms): ${(error as Error).message}`
+ `${this.chargingStation.logPrefix()} Direct authentication with ${strategyName} failed (${String(duration)}ms): ${error instanceof Error ? error.message : String(error)}`
)
throw error
}
}
} catch (error) {
logger.debug(
- `${this.chargingStation.logPrefix()} Local authorization check failed: ${(error as Error).message}`
+ `${this.chargingStation.logPrefix()} Local authorization check failed: ${error instanceof Error ? error.message : String(error)}`
)
}
}
} catch (error) {
this.sendResponse(
this.buildProtocolResponse(uuid, {
- errorMessage: (error as Error).message,
- errorStack: (error as Error).stack,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorStack: error instanceof Error ? error.stack : undefined,
status: ResponseStatus.FAILURE,
})
)
}
return [username, password]
} catch (error) {
- next(new BaseError(`Invalid basic authentication token format: ${(error as Error).message}`))
+ next(
+ new BaseError(
+ `Invalid basic authentication token format: ${error instanceof Error ? error.message : String(error)}`
+ )
+ )
return undefined
}
}
import type { AbstractUIServer } from '../AbstractUIServer.js'
-import { BaseError, type OCPPError } from '../../../exception/index.js'
+import { BaseError, OCPPError } from '../../../exception/index.js'
import {
BroadcastChannelProcedureName,
type BroadcastChannelRequestPayload,
logger.error(`${this.logPrefix(moduleName, 'requestHandler')} Handle request error:`, error)
responsePayload = {
command,
- errorDetails: (error as OCPPError).details,
- errorMessage: (error as OCPPError).message,
- errorStack: (error as OCPPError).stack,
+ errorDetails: error instanceof OCPPError ? error.details : undefined,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorStack: error instanceof Error ? error.stack : undefined,
hashIds: requestPayload?.hashIds,
requestPayload,
responsePayload,
succeededStationInfos.push(stationInfo)
}
} catch (error) {
- err = error as Error
+ err = error instanceof Error ? error : new Error(String(error))
if (stationInfo != null) {
failedStationInfos.push(stationInfo)
}
} satisfies ResponsePayload
} catch (error) {
return {
- errorMessage: (error as Error).message,
- errorStack: (error as Error).stack,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorStack: error instanceof Error ? error.stack : undefined,
status: ResponseStatus.FAILURE,
} satisfies ResponsePayload
}
} satisfies ResponsePayload
} catch (error) {
return {
- errorMessage: (error as Error).message,
- errorStack: (error as Error).stack,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorStack: error instanceof Error ? error.stack : undefined,
status: ResponseStatus.FAILURE,
} satisfies ResponsePayload
}
return { status: ResponseStatus.SUCCESS }
} catch (error) {
return {
- errorMessage: (error as Error).message,
- errorStack: (error as Error).stack,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorStack: error instanceof Error ? error.stack : undefined,
status: ResponseStatus.FAILURE,
} satisfies ResponsePayload
}
return { status: ResponseStatus.SUCCESS }
} catch (error) {
return {
- errorMessage: (error as Error).message,
- errorStack: (error as Error).stack,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorStack: error instanceof Error ? error.stack : undefined,
status: ResponseStatus.FAILURE,
} satisfies ResponsePayload
}
handleFileException(
this.dbName,
FileType.PerformanceRecords,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix
)
}
handleFileException(
this.dbName,
FileType.PerformanceRecords,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix
)
}
handleFileException(
this.dbName,
FileType.PerformanceRecords,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
this.logPrefix
)
})
delete this.orm
}
} catch (error) {
- this.handleDBStorageError(this.storageType, error as Error)
+ this.handleDBStorageError(
+ this.storageType,
+ error instanceof Error ? error : new Error(String(error))
+ )
}
}
}
}
} catch (error) {
- this.handleDBStorageError(this.storageType, error as Error)
+ this.handleDBStorageError(
+ this.storageType,
+ error instanceof Error ? error : new Error(String(error))
+ )
}
}
} catch (error) {
this.handleDBStorageError(
this.storageType,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
Constants.PERFORMANCE_RECORDS_TABLE
)
}
this.opened = false
}
} catch (error) {
- this.handleDBStorageError(StorageType.MONGO_DB, error as Error)
+ this.handleDBStorageError(
+ StorageType.MONGO_DB,
+ error instanceof Error ? error : new Error(String(error))
+ )
}
}
this.opened = true
}
} catch (error) {
- this.handleDBStorageError(StorageType.MONGO_DB, error as Error)
+ this.handleDBStorageError(
+ StorageType.MONGO_DB,
+ error instanceof Error ? error : new Error(String(error))
+ )
}
}
} catch (error) {
this.handleDBStorageError(
StorageType.MONGO_DB,
- error as Error,
+ error instanceof Error ? error : new Error(String(error)),
Constants.PERFORMANCE_RECORDS_TABLE
)
}
handleFileException(
Configuration.configurationFile,
FileType.Configuration,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
logPrefix(),
{ consoleOut: true }
)
handleFileException(
Configuration.configurationFile,
FileType.Configuration,
- error as NodeJS.ErrnoException,
+ error instanceof Error ? error : new Error(String(error)),
logPrefix(),
{ consoleOut: true }
)
try {
return watch(file, listener)
} catch (error) {
- handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
- throwError: false,
- })
+ handleFileException(
+ file,
+ fileType,
+ error instanceof Error ? error : new Error(String(error)),
+ logPrefix,
+ {
+ throwError: false,
+ }
+ )
}
} else {
logger.info(`${logPrefix} No ${fileType} file to watch given. Not monitoring its changes`)