UNPKG

@scaleway/sdk-client

Version:
30 lines (29 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const json = require("../../../helpers/json.cjs"); const scwError = require("../scw-error.cjs"); const buildMessage = (list) => `insufficient permissions: ${list.map(({ action, resource }) => `${action} ${resource}`).join("; ")}`; class PermissionsDeniedError extends scwError.ScalewayError { constructor(status, body, list) { super(status, body, buildMessage(list)); this.status = status; this.body = body; this.list = list; this.name = "PermissionsDeniedError"; } static fromJSON(status, obj) { if (!Array.isArray(obj.details)) return null; return new PermissionsDeniedError( status, obj, obj.details.reduce( (list, detail) => json.isJSONObject(detail) && typeof detail.resource === "string" && typeof detail.action === "string" ? list.concat({ action: detail.action, resource: detail.resource }) : list, [] ) ); } } exports.PermissionsDeniedError = PermissionsDeniedError;