-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patherrors.ts
More file actions
69 lines (61 loc) · 2.21 KB
/
errors.ts
File metadata and controls
69 lines (61 loc) · 2.21 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
69
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { isRestError } from "@azure/core-rest-pipeline";
/**
* Error thrown when an operation cannot be performed by the Azure App Configuration provider.
*/
export class InvalidOperationError extends Error {
constructor(message: string) {
super(message);
this.name = "InvalidOperationError";
}
}
/**
* Error thrown when an input argument is invalid.
*/
export class ArgumentError extends Error {
constructor(message: string) {
super(message);
this.name = "ArgumentError";
}
}
/**
* Error thrown when a Key Vault reference cannot be resolved.
*/
export class KeyVaultReferenceError extends Error {
constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = "KeyVaultReferenceError";
}
}
export class SnapshotReferenceError extends Error {
constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = "SnapshotReferenceError";
}
}
export function isFailoverableError(error: any): boolean {
if (!isRestError(error)) {
return false;
}
// https://nodejs.org/api/errors.html#common-system-errors
// ENOTFOUND: DNS lookup failed, ENOENT: no such file or directory, ECONNREFUSED: connection refused, ECONNRESET: connection reset by peer, ETIMEDOUT: connection timed out
if (error.code !== undefined &&
(error.code === "ENOTFOUND" || error.code === "ENOENT" || error.code === "ECONNREFUSED" || error.code === "ECONNRESET" || error.code === "ETIMEDOUT")) {
return true;
}
// 401 Unauthorized, 403 Forbidden, 408 Request Timeout, 429 Too Many Requests, 5xx Server Errors
if (error.statusCode !== undefined &&
(error.statusCode === 401 || error.statusCode === 403 || error.statusCode === 408 || error.statusCode === 429 || error.statusCode >= 500)) {
return true;
}
return false;
}
/**
* Check if the error is an instance of ArgumentError, TypeError, or RangeError.
*/
export function isInputError(error: any): boolean {
return error instanceof ArgumentError ||
error instanceof TypeError ||
error instanceof RangeError;
}