|
1 |
| -interface ErrorInfoValues { |
2 |
| - message: string; |
3 |
| - code: number; |
4 |
| - statusCode: number; |
5 |
| -} |
| 1 | +import { ErrorInfo } from 'ably'; |
6 | 2 |
|
7 |
| -// TODO: export ErrorInfo from ably-js and use that instead. |
8 |
| -export class ErrorInfo extends Error { |
9 |
| - code: number; |
10 |
| - statusCode: number; |
| 3 | +export const ERR_SPACE_NAME_MISSING = () => new ErrorInfo('must have a non-empty name for the space', 101000, 400); |
11 | 4 |
|
12 |
| - constructor({ message, code, statusCode }: ErrorInfoValues) { |
13 |
| - super(message); |
| 5 | +export const ERR_NOT_ENTERED_SPACE = () => new ErrorInfo('must enter a space to perform this operation', 101001, 400); |
14 | 6 |
|
15 |
| - if (typeof Object.setPrototypeOf !== 'undefined') { |
16 |
| - Object.setPrototypeOf(this, ErrorInfo.prototype); |
17 |
| - } |
| 7 | +export const ERR_LOCK_REQUEST_EXISTS = () => new ErrorInfo('lock request already exists', 101002, 400); |
18 | 8 |
|
19 |
| - this.code = code; |
20 |
| - this.statusCode = statusCode; |
21 |
| - } |
22 |
| -} |
23 |
| - |
24 |
| -export const ERR_SPACE_NAME_MISSING = () => |
25 |
| - new ErrorInfo({ |
26 |
| - message: 'must have a non-empty name for the space', |
27 |
| - code: 101000, |
28 |
| - statusCode: 400, |
29 |
| - }); |
30 |
| - |
31 |
| -export const ERR_NOT_ENTERED_SPACE = () => |
32 |
| - new ErrorInfo({ |
33 |
| - message: 'must enter a space to perform this operation', |
34 |
| - code: 101001, |
35 |
| - statusCode: 400, |
36 |
| - }); |
37 |
| - |
38 |
| -export const ERR_LOCK_REQUEST_EXISTS = () => |
39 |
| - new ErrorInfo({ |
40 |
| - message: 'lock request already exists', |
41 |
| - code: 101002, |
42 |
| - statusCode: 400, |
43 |
| - }); |
44 |
| - |
45 |
| -export const ERR_LOCK_IS_LOCKED = () => |
46 |
| - new ErrorInfo({ |
47 |
| - message: 'lock is currently locked', |
48 |
| - code: 101003, |
49 |
| - statusCode: 400, |
50 |
| - }); |
| 9 | +export const ERR_LOCK_IS_LOCKED = () => new ErrorInfo('lock is currently locked', 101003, 400); |
51 | 10 |
|
52 | 11 | export const ERR_LOCK_INVALIDATED = () =>
|
53 |
| - new ErrorInfo({ |
54 |
| - message: 'lock was invalidated by a concurrent lock request which now holds the lock', |
55 |
| - code: 101004, |
56 |
| - statusCode: 400, |
57 |
| - }); |
| 12 | + new ErrorInfo('lock was invalidated by a concurrent lock request which now holds the lock', 101004, 400); |
0 commit comments