UNPKG

@scaleway/sdk-client

Version:
33 lines (32 loc) 955 B
import { ScalewayError } from "../scw-error.js"; const buildMessage = (precondition, helpMessage) => { let message = `precondition failed: ${precondition}`; if (typeof helpMessage === "string" && helpMessage.length > 0) { message = message.concat(", ", helpMessage); } return message; }; class PreconditionFailedError extends ScalewayError { constructor(status, body, precondition, helpMessage) { super(status, body, buildMessage(precondition, helpMessage)); this.status = status; this.body = body; this.precondition = precondition; this.helpMessage = helpMessage; this.name = "PreconditionFailedError"; } static fromJSON(status, obj) { if (typeof obj.precondition !== "string" || typeof obj.help_message !== "string") { return null; } return new PreconditionFailedError( status, obj, obj.precondition, obj.help_message ); } } export { PreconditionFailedError };