-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patherrors.ts
More file actions
68 lines (64 loc) · 2.27 KB
/
Copy patherrors.ts
File metadata and controls
68 lines (64 loc) · 2.27 KB
1
2
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { WebServiceClientError } from './types.js';
/* tslint:disable:max-classes-per-file */
export class ArgumentError extends Error {
constructor(message: string) {
super(message);
this.name = this.constructor.name;
}
}
/**
* An error returned by the minFraud web service or encountered while
* communicating with it.
*
* In addition to the standard `Error` properties (including `cause`, which
* holds the underlying error when one exists, such as the network error
* behind a `FETCH_ERROR`), it exposes the `code`, `status`, and `url`
* associated with the failure.
*/
export class WebServiceError extends Error implements WebServiceClientError {
/**
* The error code returned by the web service or generated by this client.
*/
public readonly code: string;
/**
* A human-readable description of the error. This is an alias of `message`,
* retained for backward compatibility.
*/
public readonly error: string;
/**
* The HTTP status code, when the error originated from an HTTP response.
*
* Declared with `declare` so that no class field is emitted: the property is
* absent (rather than set to `undefined`) when no status applies, e.g. on
* network-level errors such as `FETCH_ERROR` and `NETWORK_TIMEOUT`.
*/
declare public readonly status?: number;
/**
* The URL that was being requested when the error occurred.
*/
public readonly url: string;
constructor(
properties: {
code: string;
error: string;
status?: number;
url: string;
},
options?: { cause?: unknown }
) {
super(properties.error, options);
this.code = properties.code;
this.error = properties.error;
// Only assign `status` when present so it stays genuinely optional: on
// network-level errors (e.g. FETCH_ERROR, NETWORK_TIMEOUT) the instance
// carries no `status` property at all, rather than `status: undefined`.
if (properties.status !== undefined) {
this.status = properties.status;
}
this.url = properties.url;
}
}
// Set `name` on the prototype rather than in the constructor. Using a string
// literal keeps the name correct under minification, and keeping it off the
// instance means it stays out of `JSON.stringify` output.
WebServiceError.prototype.name = 'WebServiceError';