UNPKG

@scaleway/sdk-client

Version:
24 lines (23 loc) 867 B
import { isUUID } from "../../../internal/validations/string-validation.js"; import { ScalewayError } from "../scw-error.js"; import { ResourceNotFoundError } from "../standard/resource-not-found-error.js"; class UnknownResourceMapper { static fromJSON(status, obj) { const messageParts = typeof obj.message === "string" ? obj.message.split(/"|'/) : []; if (messageParts.length === 3 && isUUID(messageParts[1])) { return new ResourceNotFoundError( status, obj, // transform `Security group ` to `security_group` // `.replaceAll()` may be too recent to use yet. // that's why we're using `.split(' ').join('_')` for now. messageParts[0].trim().toLowerCase().split(" ").join("_"), messageParts[1] ); } return new ScalewayError(status, obj); } } export { UnknownResourceMapper };