command,
requestPayload,
commandResponse: commandResponse as CommandResponse,
- errorMessage: (error as Error).message,
- errorStack: (error as Error).stack,
+ errorMessage: (error as OCPPError).message,
+ errorStack: (error as OCPPError).stack,
errorDetails: (error as OCPPError).details,
};
} finally {
type ResponseCallback,
type ResponseType,
} from '../../types';
-import {
- Constants,
- cloneObject,
- handleSendMessageError,
- isNullOrUndefined,
- logger,
-} from '../../utils';
+import { cloneObject, handleSendMessageError, isNullOrUndefined, logger } from '../../utils';
const moduleName = 'OCPPRequestService';
ErrorType.GENERIC_ERROR,
`Timeout for message id '${messageId}'`,
commandName,
- (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FROZEN_OBJECT,
+ (messagePayload as OCPPError).details,
),
);
}, OCPPConstants.OCPP_WEBSOCKET_TIMEOUT);
params?.skipBufferingOnError === false ? '' : 'non '
}buffered message id '${messageId}' with content '${messageToSend}'`,
commandName,
- (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FROZEN_OBJECT,
+ (messagePayload as JsonObject).details,
),
);
}
messageToSend = JSON.stringify([
messageType,
messageId,
- (messagePayload as OCPPError)?.code ?? ErrorType.GENERIC_ERROR,
- (messagePayload as OCPPError)?.message ?? '',
- (messagePayload as OCPPError)?.details ?? { commandName },
+ (messagePayload as OCPPError).code,
+ (messagePayload as OCPPError).message,
+ (messagePayload as OCPPError).details ?? {
+ command: (messagePayload as OCPPError).command ?? commandName,
+ },
] as ErrorResponse);
break;
}
command,
requestPayload,
responsePayload,
- errorMessage: (error as Error).message,
- errorStack: (error as Error).stack,
+ errorMessage: (error as OCPPError).message,
+ errorStack: (error as OCPPError).stack,
errorDetails: (error as OCPPError).details,
};
}
super(message);
this.name = new.target.name;
Object.setPrototypeOf(this, new.target.prototype);
- Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : this.createStack();
+ typeof Error.captureStackTrace === 'function'
+ ? Error.captureStackTrace(this, this.constructor)
+ : this.createStack();
}
private createStack(): void {
) {
super(message);
- this.code = code ?? ErrorType.GENERIC_ERROR;
- this.command = command;
- this.details = details ?? Constants.EMPTY_FROZEN_OBJECT;
+ this.code = code;
+ this.command =
+ command ?? (Constants.UNKNOWN_COMMAND as RequestCommand | IncomingRequestCommand);
+ this.details = details;
}
}