-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.ts
98 lines (87 loc) · 2.92 KB
/
errors.ts
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { DfuTargetId } from "./events";
/**
* Parent class for all DFU errors.
* @see Error codes in Nordic DFU library source code, in file
* <a href="https://github.com/NordicSemiconductor/Android-DFU-Library/blob/main/lib/dfu/src/main/java/no/nordicsemi/android/error/GattError.java">GattError.java</a>.
*/
export class DfuError extends Error {
readonly target: DfuTargetId;
constructor(target: DfuTargetId, message?: string) {
super(message);
this.name = "DfuError";
this.target = target;
}
}
/** Internal error, a bug occurred. */
export class DfuInternalError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuInternalError";
}
}
/** The method was passed an invalid argument. */
export class DfuInvalidArgumentError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuInvalidArgumentError";
}
}
/** A DFU is already on-going. */
export class DfuBusyError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuBusyError";
}
}
/** Bluetooth connection error. */
export class DfuConnectionError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuConnectionError";
}
}
/** Bluetooth communication error. */
export class DfuCommunicationError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuCommunicationError";
}
}
/** Error during DFU originating from the target device. */
export class DfuRemoteError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuRemoteError";
}
}
/** DFU error thrown when the given file is invalid or wasn't found. */
export class DfuFileInvalidError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuFileInvalidError";
}
}
/**
* DFU error thrown when the Nordic DFU BLE service hasn't been discovered
* on the target device.
*/
export class DfuDeviceNotSupportedError extends DfuCommunicationError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuDeviceNotSupportedError";
}
}
/** DFU error thrown when the update fails because of the firmware version was rejected. */
export class DfuFirmwareVersionFailureError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuFirmwareVersionFailureError";
}
}
/** DFU error thrown when the update fails because of the device disconnected. */
export class DfuDeviceDisconnectedError extends DfuError {
constructor(target: DfuTargetId, message?: string) {
super(target, message);
this.name = "DfuDeviceDisconnectedError";
}
}