adapty 0.6.0-beta.0 → 0.6.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.
@@ -29,9 +29,11 @@ export declare class ApiError extends Error {
29
29
  statusCode: number;
30
30
  errorCode: string;
31
31
  fieldErrors: Record<string, string[]>;
32
+ code?: string;
32
33
  detail?: string;
33
34
  retryAfterSeconds?: number;
34
35
  constructor(statusCode: number, errorCode: string, fieldErrors: Record<string, string[]>, opts?: ApiErrorOptions);
36
+ private static humanMessage;
35
37
  toHuman(): string;
36
38
  toJSON(): ApiErrorBody;
37
39
  }
@@ -8,16 +8,34 @@ export class ApiError extends Error {
8
8
  statusCode;
9
9
  errorCode;
10
10
  fieldErrors;
11
+ // Read by oclif's prettyPrint to render a `Code: ...` line under the message.
12
+ code;
11
13
  detail;
12
14
  retryAfterSeconds;
13
15
  constructor(statusCode, errorCode, fieldErrors, opts = {}) {
14
- super(opts.detail ?? errorCode);
16
+ // `message` is what oclif's default error renderer prints. Prefer the server's human text (an ASA
17
+ // `detail` or the developer API's field errors) over the bare code, which reads as gibberish on its own.
18
+ super(ApiError.humanMessage(errorCode, fieldErrors, opts.detail));
15
19
  this.statusCode = statusCode;
16
20
  this.errorCode = errorCode;
17
21
  this.fieldErrors = fieldErrors;
18
22
  this.name = 'ApiError';
19
23
  this.detail = opts.detail;
20
24
  this.retryAfterSeconds = opts.retryAfterSeconds;
25
+ // Surface real server codes as a secondary line; hide synthetic `http_<status>` fallbacks.
26
+ if (!errorCode.startsWith('http_'))
27
+ this.code = errorCode;
28
+ }
29
+ static humanMessage(errorCode, fieldErrors, detail) {
30
+ if (detail)
31
+ return detail;
32
+ const parts = [];
33
+ for (const [field, msgs] of Object.entries(fieldErrors)) {
34
+ for (const msg of msgs) {
35
+ parts.push(field === 'non_field_errors' ? msg : `${field}: ${msg}`);
36
+ }
37
+ }
38
+ return parts.length > 0 ? parts.join('; ') : errorCode;
21
39
  }
22
40
  toHuman() {
23
41
  const lines = [`Error: ${this.errorCode}`];