@scaleway/sdk-client 2.1.0 → 2.2.1

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.
Files changed (53) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/helpers/is-browser.js +1 -3
  3. package/dist/helpers/is-response.js +8 -3
  4. package/dist/helpers/json.js +47 -40
  5. package/dist/helpers/marshalling.js +88 -59
  6. package/dist/index.js +6 -47
  7. package/dist/internal/async/interval-retrier.js +64 -49
  8. package/dist/internal/async/sleep.js +10 -4
  9. package/dist/internal/interceptors/composer.js +34 -23
  10. package/dist/internal/interceptors/helpers.js +22 -9
  11. package/dist/internal/logger/console-logger.js +27 -22
  12. package/dist/internal/logger/index.js +23 -7
  13. package/dist/internal/logger/level-resolver.js +9 -12
  14. package/dist/internal/validations/string-validation.js +20 -21
  15. package/dist/internals.js +8 -0
  16. package/dist/package.js +32 -0
  17. package/dist/scw/api.js +10 -7
  18. package/dist/scw/auth.js +60 -17
  19. package/dist/scw/client-ini-factory.js +127 -57
  20. package/dist/scw/client-ini-profile.js +23 -19
  21. package/dist/scw/client-settings.js +25 -49
  22. package/dist/scw/client.js +76 -25
  23. package/dist/scw/constants.js +3 -8
  24. package/dist/scw/custom-marshalling.js +147 -121
  25. package/dist/scw/custom-types.js +11 -10
  26. package/dist/scw/errors/error-parser.js +83 -61
  27. package/dist/scw/errors/non-standard/invalid-request-mapper.js +20 -29
  28. package/dist/scw/errors/non-standard/unknown-resource-mapper.js +9 -16
  29. package/dist/scw/errors/scw-error.js +42 -39
  30. package/dist/scw/errors/standard/already-exists-error.js +20 -29
  31. package/dist/scw/errors/standard/denied-authentication-error.js +43 -34
  32. package/dist/scw/errors/standard/index.js +20 -18
  33. package/dist/scw/errors/standard/invalid-arguments-error.js +51 -50
  34. package/dist/scw/errors/standard/out-of-stock-error.js +18 -15
  35. package/dist/scw/errors/standard/permissions-denied-error.js +30 -26
  36. package/dist/scw/errors/standard/precondition-failed-error.js +32 -29
  37. package/dist/scw/errors/standard/quotas-exceeded-error.js +43 -38
  38. package/dist/scw/errors/standard/resource-expired-error.js +20 -29
  39. package/dist/scw/errors/standard/resource-locked-error.js +19 -18
  40. package/dist/scw/errors/standard/resource-not-found-error.js +19 -22
  41. package/dist/scw/errors/standard/too-many-requests-error.js +41 -54
  42. package/dist/scw/errors/standard/transient-state-error.js +20 -29
  43. package/dist/scw/errors/types.js +12 -12
  44. package/dist/scw/fetch/build-fetcher.js +49 -54
  45. package/dist/scw/fetch/http-dumper.js +50 -16
  46. package/dist/scw/fetch/http-interceptors.d.ts +1 -3
  47. package/dist/scw/fetch/http-interceptors.js +52 -34
  48. package/dist/scw/fetch/resource-paginator.js +52 -28
  49. package/dist/scw/fetch/response-parser.js +48 -49
  50. package/dist/scw/locality.js +12 -14
  51. package/dist/vendor/base64/index.js +31 -39
  52. package/package.json +1 -1
  53. 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
- const messageParts = typeof obj.message === "string" ? obj.message.split(/"|'/) : [];
6
- if (messageParts.length === 3 && isUUID(messageParts[1])) {
7
- return new ResourceNotFoundError(
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
- const buildDefaultMessage = (status, body) => {
4
- const message = [`http error ${status}`];
5
- if (typeof body === "string") {
6
- message.push(body);
7
- } else if (isJSONObject(body)) {
8
- if (typeof body.resource === "string") {
9
- message.push(`resource ${body.resource}`);
10
- }
11
- if (typeof body.message === "string") {
12
- message.push(body.message);
13
- }
14
- if (body.fields && isRecordOfStringArray(body.fields)) {
15
- message.push(
16
- Object.entries(body.fields).map(([name, list]) => `${name} (${list.join(", ")})`).join(", ")
17
- );
18
- }
19
- }
20
- return message.join(": ");
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
- class ScalewayError extends Error {
23
- constructor(status, body, message = buildDefaultMessage(status, body)) {
24
- super(message);
25
- this.status = status;
26
- this.body = body;
27
- this.message = message;
28
- this.name = "ScalewayError";
29
- this.rawMessage = typeof body === "object" && typeof body.message === "string" ? body.message : void 0;
30
- Object.setPrototypeOf(this, new.target.prototype);
31
- }
32
- /** The message originating from the payload. */
33
- rawMessage;
34
- static fromJSON(status, obj) {
35
- return new ScalewayError(status, obj);
36
- }
37
- toString() {
38
- return `${this.name}: ${this.message}`;
39
- }
40
- }
41
- export {
42
- ScalewayError
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
- class AlreadyExistsError extends ScalewayError {
3
- constructor(status, body, resource, resourceId, helpMessage) {
4
- super(
5
- status,
6
- body,
7
- `resource ${resource} with ID ${resourceId} already exists: ${helpMessage}`
8
- );
9
- this.status = status;
10
- this.body = body;
11
- this.resource = resource;
12
- this.resourceId = resourceId;
13
- this.helpMessage = helpMessage;
14
- this.name = "AlreadyExistsError";
15
- }
16
- static fromJSON(status, obj) {
17
- if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string" || typeof obj.help_message !== "string") {
18
- return null;
19
- }
20
- return new AlreadyExistsError(
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
- const buildMessage = (method, reason) => {
3
- let reasonDesc;
4
- switch (reason) {
5
- case "invalid_argument":
6
- reasonDesc = `invalid ${method} format or empty value`;
7
- break;
8
- case "not_found":
9
- reasonDesc = `${method} does not exist`;
10
- break;
11
- case "expired":
12
- reasonDesc = `${method} is expired`;
13
- break;
14
- default:
15
- reasonDesc = `unknown reason for ${method}`;
16
- }
17
- return `denied authentication: ${reasonDesc}`;
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
- class DeniedAuthenticationError extends ScalewayError {
20
- constructor(status, body, method, reason) {
21
- super(status, body, buildMessage(method, reason));
22
- this.status = status;
23
- this.body = body;
24
- this.method = method;
25
- this.reason = reason;
26
- this.name = "DeniedAuthenticationError";
27
- }
28
- static fromJSON(status, obj) {
29
- if (typeof obj.method !== "string" || typeof obj.reason !== "string") {
30
- return null;
31
- }
32
- return new DeniedAuthenticationError(status, obj, obj.method, obj.reason);
33
- }
34
- }
35
- export {
36
- DeniedAuthenticationError
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
- export {
15
- AlreadyExistsError,
16
- DeniedAuthenticationError,
17
- InvalidArgumentsError,
18
- OutOfStockError,
19
- PermissionsDeniedError,
20
- PreconditionFailedError,
21
- QuotasExceededError,
22
- ResourceExpiredError,
23
- ResourceLockedError,
24
- ResourceNotFoundError,
25
- ScalewayError,
26
- TooManyRequestsError,
27
- TransientStateError
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
- const buildMessage = (list) => {
4
- const invalidArgs = list.reduce((acc, details) => {
5
- let readableReason = "";
6
- switch (details.reason) {
7
- case "required":
8
- readableReason = `is required`;
9
- break;
10
- case "format":
11
- readableReason = `is wrongly formatted`;
12
- break;
13
- case "constraint":
14
- readableReason = `does not respect constraint`;
15
- break;
16
- default:
17
- readableReason = `is invalid for unexpected reason`;
18
- break;
19
- }
20
- if (details.helpMessage && details.helpMessage.length > 0) {
21
- readableReason = readableReason.concat(`, `, details.helpMessage);
22
- }
23
- acc.push(`${details.argumentName} ${readableReason}`);
24
- return acc;
25
- }, []);
26
- return `invalid argument(s): ${invalidArgs.join("; ")}`;
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
- class InvalidArgumentsError extends ScalewayError {
29
- constructor(status, body, details) {
30
- super(status, body, buildMessage(details));
31
- this.status = status;
32
- this.body = body;
33
- this.details = details;
34
- this.name = "InvalidArgumentsError";
35
- }
36
- static fromJSON(status, obj) {
37
- if (!Array.isArray(obj.details)) return null;
38
- return new InvalidArgumentsError(
39
- status,
40
- obj,
41
- obj.details.reduce(
42
- (list, detail) => isJSONObject(detail) && typeof detail.argument_name === "string" && typeof detail.reason === "string" ? list.concat({
43
- argumentName: detail.argument_name,
44
- helpMessage: typeof detail.help_message === "string" ? detail.help_message : void 0,
45
- reason: detail.reason
46
- }) : list,
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
- class OutOfStockError extends ScalewayError {
3
- constructor(status, body, resource) {
4
- super(status, body, `resource ${resource} is out of stock`);
5
- this.status = status;
6
- this.body = body;
7
- this.resource = resource;
8
- this.name = "OutOfStockError";
9
- }
10
- static fromJSON(status, obj) {
11
- if (typeof obj.resource !== "string") return null;
12
- return new OutOfStockError(status, obj, obj.resource);
13
- }
14
- }
15
- export {
16
- OutOfStockError
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
- const buildMessage = (list) => `insufficient permissions: ${list.map(({ action, resource }) => `${action} ${resource}`).join("; ")}`;
4
- class PermissionsDeniedError extends ScalewayError {
5
- constructor(status, body, list) {
6
- super(status, body, buildMessage(list));
7
- this.status = status;
8
- this.body = body;
9
- this.list = list;
10
- this.name = "PermissionsDeniedError";
11
- }
12
- static fromJSON(status, obj) {
13
- if (!Array.isArray(obj.details)) return null;
14
- return new PermissionsDeniedError(
15
- status,
16
- obj,
17
- obj.details.reduce(
18
- (list, detail) => isJSONObject(detail) && typeof detail.resource === "string" && typeof detail.action === "string" ? list.concat({
19
- action: detail.action,
20
- resource: detail.resource
21
- }) : list,
22
- []
23
- )
24
- );
25
- }
26
- }
27
- export {
28
- PermissionsDeniedError
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
- const buildMessage = (precondition, helpMessage) => {
3
- let message = `precondition failed: ${precondition}`;
4
- if (typeof helpMessage === "string" && helpMessage.length > 0) {
5
- message = message.concat(", ", helpMessage);
6
- }
7
- return message;
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
- class PreconditionFailedError extends ScalewayError {
10
- constructor(status, body, precondition, helpMessage) {
11
- super(status, body, buildMessage(precondition, helpMessage));
12
- this.status = status;
13
- this.body = body;
14
- this.precondition = precondition;
15
- this.helpMessage = helpMessage;
16
- this.name = "PreconditionFailedError";
17
- }
18
- static fromJSON(status, obj) {
19
- if (typeof obj.precondition !== "string" || typeof obj.help_message !== "string") {
20
- return null;
21
- }
22
- return new PreconditionFailedError(
23
- status,
24
- obj,
25
- obj.precondition,
26
- obj.help_message
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 };