@scaleway/sdk-client 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.js +11 -0
- package/dist/helpers/is-browser.js +1 -3
- package/dist/helpers/is-response.js +8 -3
- package/dist/helpers/json.js +47 -40
- package/dist/helpers/marshalling.js +88 -59
- package/dist/index.js +6 -47
- package/dist/internal/async/interval-retrier.js +64 -49
- package/dist/internal/async/sleep.js +10 -4
- package/dist/internal/interceptors/composer.js +34 -23
- package/dist/internal/interceptors/helpers.js +22 -9
- package/dist/internal/logger/console-logger.js +27 -22
- package/dist/internal/logger/index.js +23 -7
- package/dist/internal/logger/level-resolver.js +9 -12
- package/dist/internal/validations/string-validation.js +20 -21
- package/dist/internals.js +8 -0
- package/dist/package.js +32 -0
- package/dist/scw/api.js +10 -7
- package/dist/scw/auth.js +60 -17
- package/dist/scw/client-ini-factory.js +127 -57
- package/dist/scw/client-ini-profile.js +23 -19
- package/dist/scw/client-settings.js +25 -49
- package/dist/scw/client.js +76 -25
- package/dist/scw/constants.js +3 -8
- package/dist/scw/custom-marshalling.js +147 -121
- package/dist/scw/custom-types.js +11 -10
- package/dist/scw/errors/error-parser.js +83 -61
- package/dist/scw/errors/non-standard/invalid-request-mapper.js +20 -29
- package/dist/scw/errors/non-standard/unknown-resource-mapper.js +9 -16
- package/dist/scw/errors/scw-error.js +42 -39
- package/dist/scw/errors/standard/already-exists-error.js +20 -29
- package/dist/scw/errors/standard/denied-authentication-error.js +43 -34
- package/dist/scw/errors/standard/index.js +20 -18
- package/dist/scw/errors/standard/invalid-arguments-error.js +51 -50
- package/dist/scw/errors/standard/out-of-stock-error.js +18 -15
- package/dist/scw/errors/standard/permissions-denied-error.js +30 -26
- package/dist/scw/errors/standard/precondition-failed-error.js +32 -29
- package/dist/scw/errors/standard/quotas-exceeded-error.js +43 -38
- package/dist/scw/errors/standard/resource-expired-error.js +20 -29
- package/dist/scw/errors/standard/resource-locked-error.js +19 -18
- package/dist/scw/errors/standard/resource-not-found-error.js +19 -22
- package/dist/scw/errors/standard/too-many-requests-error.js +41 -54
- package/dist/scw/errors/standard/transient-state-error.js +20 -29
- package/dist/scw/errors/types.js +12 -12
- package/dist/scw/fetch/build-fetcher.js +49 -54
- package/dist/scw/fetch/http-dumper.js +50 -16
- package/dist/scw/fetch/http-interceptors.d.ts +1 -3
- package/dist/scw/fetch/http-interceptors.js +52 -34
- package/dist/scw/fetch/resource-paginator.js +52 -28
- package/dist/scw/fetch/response-parser.js +48 -49
- package/dist/scw/locality.js +12 -14
- package/dist/vendor/base64/index.js +31 -39
- package/package.json +1 -1
- package/dist/package.json.js +0 -8
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { isUUID } from "../../../internal/validations/string-validation.js";
|
|
2
2
|
import { ScalewayError } from "../scw-error.js";
|
|
3
3
|
import { ResourceNotFoundError } from "../standard/resource-not-found-error.js";
|
|
4
|
+
/**
|
|
5
|
+
* UnknownResource error is only returned by the instance API.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
4
9
|
const mapUnknownResourceFromJSON = (status, obj) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
status,
|
|
9
|
-
obj,
|
|
10
|
-
// transform `Security group ` to `security_group`
|
|
11
|
-
// `.replaceAll()` may be too recent to use yet.
|
|
12
|
-
// that's why we're using `.split(' ').join('_')` for now.
|
|
13
|
-
messageParts[0].trim().toLowerCase().split(" ").join("_"),
|
|
14
|
-
messageParts[1]
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
return new ScalewayError(status, obj);
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
mapUnknownResourceFromJSON
|
|
10
|
+
const messageParts = typeof obj.message === "string" ? obj.message.split(/"|'/) : [];
|
|
11
|
+
if (messageParts.length === 3 && isUUID(messageParts[1])) return new ResourceNotFoundError(status, obj, messageParts[0].trim().toLowerCase().split(" ").join("_"), messageParts[1]);
|
|
12
|
+
return new ScalewayError(status, obj);
|
|
21
13
|
};
|
|
14
|
+
export { mapUnknownResourceFromJSON };
|
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
import { isJSONObject } from "../../helpers/json.js";
|
|
2
2
|
import { isRecordOfStringArray } from "./types.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Builds the default message for {@link ScalewayError}.
|
|
5
|
+
*
|
|
6
|
+
* @param status - The response code
|
|
7
|
+
* @param body - The response body
|
|
8
|
+
* @returns The error message
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
var buildDefaultMessage = (status, body) => {
|
|
13
|
+
const message = [`http error ${status}`];
|
|
14
|
+
if (typeof body === "string") message.push(body);
|
|
15
|
+
else if (isJSONObject(body)) {
|
|
16
|
+
if (typeof body.resource === "string") message.push(`resource ${body.resource}`);
|
|
17
|
+
if (typeof body.message === "string") message.push(body.message);
|
|
18
|
+
if (body.fields && isRecordOfStringArray(body.fields)) message.push(Object.entries(body.fields).map(([name, list]) => `${name} (${list.join(", ")})`).join(", "));
|
|
19
|
+
}
|
|
20
|
+
return message.join(": ");
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Scaleway error.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
var ScalewayError = class ScalewayError extends Error {
|
|
28
|
+
/** The message originating from the payload. */
|
|
29
|
+
rawMessage;
|
|
30
|
+
constructor(status, body, message = buildDefaultMessage(status, body)) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.status = status;
|
|
33
|
+
this.body = body;
|
|
34
|
+
this.message = message;
|
|
35
|
+
this.name = "ScalewayError";
|
|
36
|
+
this.rawMessage = typeof body === "object" && typeof body.message === "string" ? body.message : void 0;
|
|
37
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
38
|
+
}
|
|
39
|
+
static fromJSON(status, obj) {
|
|
40
|
+
return new ScalewayError(status, obj);
|
|
41
|
+
}
|
|
42
|
+
toString() {
|
|
43
|
+
return `${this.name}: ${this.message}`;
|
|
44
|
+
}
|
|
43
45
|
};
|
|
46
|
+
export { ScalewayError };
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
import { ScalewayError } from "../scw-error.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
status,
|
|
22
|
-
obj,
|
|
23
|
-
obj.resource,
|
|
24
|
-
obj.resource_id,
|
|
25
|
-
obj.help_message
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
AlreadyExistsError
|
|
2
|
+
/**
|
|
3
|
+
* AlreadyExists error is used when a resource already exists.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
var AlreadyExistsError = class AlreadyExistsError extends ScalewayError {
|
|
8
|
+
constructor(status, body, resource, resourceId, helpMessage) {
|
|
9
|
+
super(status, body, `resource ${resource} with ID ${resourceId} already exists: ${helpMessage}`);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.body = body;
|
|
12
|
+
this.resource = resource;
|
|
13
|
+
this.resourceId = resourceId;
|
|
14
|
+
this.helpMessage = helpMessage;
|
|
15
|
+
this.name = "AlreadyExistsError";
|
|
16
|
+
}
|
|
17
|
+
static fromJSON(status, obj) {
|
|
18
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string" || typeof obj.help_message !== "string") return null;
|
|
19
|
+
return new AlreadyExistsError(status, obj, obj.resource, obj.resource_id, obj.help_message);
|
|
20
|
+
}
|
|
31
21
|
};
|
|
22
|
+
export { AlreadyExistsError };
|
|
@@ -1,37 +1,46 @@
|
|
|
1
1
|
import { ScalewayError } from "../scw-error.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Build the default message for {@link DeniedAuthenticationError}.
|
|
4
|
+
*
|
|
5
|
+
* @param method - The authentication method
|
|
6
|
+
* @param reason - The deny reason
|
|
7
|
+
* @returns The error message
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
var buildMessage = (method, reason) => {
|
|
12
|
+
let reasonDesc;
|
|
13
|
+
switch (reason) {
|
|
14
|
+
case "invalid_argument":
|
|
15
|
+
reasonDesc = `invalid ${method} format or empty value`;
|
|
16
|
+
break;
|
|
17
|
+
case "not_found":
|
|
18
|
+
reasonDesc = `${method} does not exist`;
|
|
19
|
+
break;
|
|
20
|
+
case "expired":
|
|
21
|
+
reasonDesc = `${method} is expired`;
|
|
22
|
+
break;
|
|
23
|
+
default: reasonDesc = `unknown reason for ${method}`;
|
|
24
|
+
}
|
|
25
|
+
return `denied authentication: ${reasonDesc}`;
|
|
18
26
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
/**
|
|
28
|
+
* DeniedAuthentication error is used by the API Gateway auth service to deny a request.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
var DeniedAuthenticationError = class DeniedAuthenticationError extends ScalewayError {
|
|
33
|
+
constructor(status, body, method, reason) {
|
|
34
|
+
super(status, body, buildMessage(method, reason));
|
|
35
|
+
this.status = status;
|
|
36
|
+
this.body = body;
|
|
37
|
+
this.method = method;
|
|
38
|
+
this.reason = reason;
|
|
39
|
+
this.name = "DeniedAuthenticationError";
|
|
40
|
+
}
|
|
41
|
+
static fromJSON(status, obj) {
|
|
42
|
+
if (typeof obj.method !== "string" || typeof obj.reason !== "string") return null;
|
|
43
|
+
return new DeniedAuthenticationError(status, obj, obj.method, obj.reason);
|
|
44
|
+
}
|
|
37
45
|
};
|
|
46
|
+
export { DeniedAuthenticationError };
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
+
import { __exportAll } from "../../../_virtual/_rolldown/runtime.js";
|
|
1
2
|
import { ScalewayError } from "../scw-error.js";
|
|
3
|
+
import { InvalidArgumentsError } from "./invalid-arguments-error.js";
|
|
4
|
+
import { QuotasExceededError } from "./quotas-exceeded-error.js";
|
|
5
|
+
import { ResourceNotFoundError } from "./resource-not-found-error.js";
|
|
2
6
|
import { AlreadyExistsError } from "./already-exists-error.js";
|
|
3
7
|
import { DeniedAuthenticationError } from "./denied-authentication-error.js";
|
|
4
|
-
import { InvalidArgumentsError } from "./invalid-arguments-error.js";
|
|
5
8
|
import { OutOfStockError } from "./out-of-stock-error.js";
|
|
6
9
|
import { PermissionsDeniedError } from "./permissions-denied-error.js";
|
|
7
10
|
import { PreconditionFailedError } from "./precondition-failed-error.js";
|
|
8
|
-
import { QuotasExceededError } from "./quotas-exceeded-error.js";
|
|
9
11
|
import { ResourceExpiredError } from "./resource-expired-error.js";
|
|
10
12
|
import { ResourceLockedError } from "./resource-locked-error.js";
|
|
11
|
-
import { ResourceNotFoundError } from "./resource-not-found-error.js";
|
|
12
13
|
import { TooManyRequestsError } from "./too-many-requests-error.js";
|
|
13
14
|
import { TransientStateError } from "./transient-state-error.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
15
|
+
var standard_exports = /* @__PURE__ */ __exportAll({
|
|
16
|
+
AlreadyExistsError: () => AlreadyExistsError,
|
|
17
|
+
DeniedAuthenticationError: () => DeniedAuthenticationError,
|
|
18
|
+
InvalidArgumentsError: () => InvalidArgumentsError,
|
|
19
|
+
OutOfStockError: () => OutOfStockError,
|
|
20
|
+
PermissionsDeniedError: () => PermissionsDeniedError,
|
|
21
|
+
PreconditionFailedError: () => PreconditionFailedError,
|
|
22
|
+
QuotasExceededError: () => QuotasExceededError,
|
|
23
|
+
ResourceExpiredError: () => ResourceExpiredError,
|
|
24
|
+
ResourceLockedError: () => ResourceLockedError,
|
|
25
|
+
ResourceNotFoundError: () => ResourceNotFoundError,
|
|
26
|
+
ScalewayError: () => ScalewayError,
|
|
27
|
+
TooManyRequestsError: () => TooManyRequestsError,
|
|
28
|
+
TransientStateError: () => TransientStateError
|
|
29
|
+
});
|
|
30
|
+
export { standard_exports };
|
|
@@ -1,54 +1,55 @@
|
|
|
1
1
|
import { isJSONObject } from "../../../helpers/json.js";
|
|
2
2
|
import { ScalewayError } from "../scw-error.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Build the default message for {@link InvalidArgumentsError}.
|
|
5
|
+
*
|
|
6
|
+
* @param list - The list of {@link InvalidArgumentsErrorDetails}
|
|
7
|
+
* @returns The error message
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
var buildMessage = (list) => {
|
|
12
|
+
return `invalid argument(s): ${list.reduce((acc, details) => {
|
|
13
|
+
let readableReason = "";
|
|
14
|
+
switch (details.reason) {
|
|
15
|
+
case "required":
|
|
16
|
+
readableReason = `is required`;
|
|
17
|
+
break;
|
|
18
|
+
case "format":
|
|
19
|
+
readableReason = `is wrongly formatted`;
|
|
20
|
+
break;
|
|
21
|
+
case "constraint":
|
|
22
|
+
readableReason = `does not respect constraint`;
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
readableReason = `is invalid for unexpected reason`;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
if (details.helpMessage && details.helpMessage.length > 0) readableReason = readableReason.concat(`, `, details.helpMessage);
|
|
29
|
+
acc.push(`${details.argumentName} ${readableReason}`);
|
|
30
|
+
return acc;
|
|
31
|
+
}, []).join("; ")}`;
|
|
27
32
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
InvalidArgumentsError
|
|
33
|
+
/**
|
|
34
|
+
* InvalidArguments error happens when one or many fields are invalid in the request message.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
var InvalidArgumentsError = class InvalidArgumentsError extends ScalewayError {
|
|
39
|
+
constructor(status, body, details) {
|
|
40
|
+
super(status, body, buildMessage(details));
|
|
41
|
+
this.status = status;
|
|
42
|
+
this.body = body;
|
|
43
|
+
this.details = details;
|
|
44
|
+
this.name = "InvalidArgumentsError";
|
|
45
|
+
}
|
|
46
|
+
static fromJSON(status, obj) {
|
|
47
|
+
if (!Array.isArray(obj.details)) return null;
|
|
48
|
+
return new InvalidArgumentsError(status, obj, obj.details.reduce((list, detail) => isJSONObject(detail) && typeof detail.argument_name === "string" && typeof detail.reason === "string" ? list.concat({
|
|
49
|
+
argumentName: detail.argument_name,
|
|
50
|
+
helpMessage: typeof detail.help_message === "string" ? detail.help_message : void 0,
|
|
51
|
+
reason: detail.reason
|
|
52
|
+
}) : list, []));
|
|
53
|
+
}
|
|
54
54
|
};
|
|
55
|
+
export { InvalidArgumentsError };
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { ScalewayError } from "../scw-error.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
/**
|
|
3
|
+
* OutOfStock error happens when stocks are empty for the resource.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
var OutOfStockError = class OutOfStockError extends ScalewayError {
|
|
8
|
+
constructor(status, body, resource) {
|
|
9
|
+
super(status, body, `resource ${resource} is out of stock`);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.body = body;
|
|
12
|
+
this.resource = resource;
|
|
13
|
+
this.name = "OutOfStockError";
|
|
14
|
+
}
|
|
15
|
+
static fromJSON(status, obj) {
|
|
16
|
+
if (typeof obj.resource !== "string") return null;
|
|
17
|
+
return new OutOfStockError(status, obj, obj.resource);
|
|
18
|
+
}
|
|
17
19
|
};
|
|
20
|
+
export { OutOfStockError };
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
import { isJSONObject } from "../../../helpers/json.js";
|
|
2
2
|
import { ScalewayError } from "../scw-error.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Build the default message for {@link PermissionsDeniedError}.
|
|
5
|
+
*
|
|
6
|
+
* @param list - The list of {@link PermissionsDeniedErrorDetails}
|
|
7
|
+
* @returns The error message
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
var buildMessage = (list) => `insufficient permissions: ${list.map(({ action, resource }) => `${action} ${resource}`).join("; ")}`;
|
|
12
|
+
/**
|
|
13
|
+
* PermissionsDenied error happens when one or many permissions are not accorded to the user making the request.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
var PermissionsDeniedError = class PermissionsDeniedError extends ScalewayError {
|
|
18
|
+
constructor(status, body, list) {
|
|
19
|
+
super(status, body, buildMessage(list));
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.body = body;
|
|
22
|
+
this.list = list;
|
|
23
|
+
this.name = "PermissionsDeniedError";
|
|
24
|
+
}
|
|
25
|
+
static fromJSON(status, obj) {
|
|
26
|
+
if (!Array.isArray(obj.details)) return null;
|
|
27
|
+
return new PermissionsDeniedError(status, obj, obj.details.reduce((list, detail) => isJSONObject(detail) && typeof detail.resource === "string" && typeof detail.action === "string" ? list.concat({
|
|
28
|
+
action: detail.action,
|
|
29
|
+
resource: detail.resource
|
|
30
|
+
}) : list, []));
|
|
31
|
+
}
|
|
29
32
|
};
|
|
33
|
+
export { PermissionsDeniedError };
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { ScalewayError } from "../scw-error.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Build the default message for {@link PreconditionFailedError}.
|
|
4
|
+
*
|
|
5
|
+
* @param precondition - The precondition
|
|
6
|
+
* @param helpMessage - The message which should help the user to fix the root cause
|
|
7
|
+
* @returns The error message
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
var buildMessage = (precondition, helpMessage) => {
|
|
12
|
+
let message = `precondition failed: ${precondition}`;
|
|
13
|
+
if (typeof helpMessage === "string" && helpMessage.length > 0) message = message.concat(", ", helpMessage);
|
|
14
|
+
return message;
|
|
8
15
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
PreconditionFailedError
|
|
16
|
+
/**
|
|
17
|
+
* PreconditionFailed error is used when a precondition is not respected.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
var PreconditionFailedError = class PreconditionFailedError extends ScalewayError {
|
|
22
|
+
constructor(status, body, precondition, helpMessage) {
|
|
23
|
+
super(status, body, buildMessage(precondition, helpMessage));
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.body = body;
|
|
26
|
+
this.precondition = precondition;
|
|
27
|
+
this.helpMessage = helpMessage;
|
|
28
|
+
this.name = "PreconditionFailedError";
|
|
29
|
+
}
|
|
30
|
+
static fromJSON(status, obj) {
|
|
31
|
+
if (typeof obj.precondition !== "string" || typeof obj.help_message !== "string") return null;
|
|
32
|
+
return new PreconditionFailedError(status, obj, obj.precondition, obj.help_message);
|
|
33
|
+
}
|
|
32
34
|
};
|
|
35
|
+
export { PreconditionFailedError };
|