@openstax/ts-utils 1.2.7 → 1.2.8

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.
@@ -6,16 +6,20 @@ export declare const isAppError: (e: any) => e is Error & {
6
6
  export declare class InvalidRequestError extends Error {
7
7
  static readonly TYPE = "InvalidRequestError";
8
8
  static matches: (e: any) => e is typeof InvalidRequestError;
9
+ constructor(message?: string);
9
10
  }
10
11
  export declare class UnauthorizedError extends Error {
11
12
  static readonly TYPE = "UnauthorizedError";
12
13
  static matches: (e: any) => e is typeof UnauthorizedError;
14
+ constructor(message?: string);
13
15
  }
14
16
  export declare class NotFoundError extends Error {
15
17
  static readonly TYPE = "NotFoundError";
16
18
  static matches: (e: any) => e is typeof NotFoundError;
19
+ constructor(message?: string);
17
20
  }
18
21
  export declare class SessionExpiredError extends Error {
19
22
  static readonly TYPE = "SessionExpiredError";
20
23
  static matches: (e: any) => e is typeof SessionExpiredError;
24
+ constructor(message?: string);
21
25
  }
@@ -15,18 +15,30 @@ const errorIsType = ({ TYPE }) => (e) => e instanceof Error
15
15
  export const isAppError = (e) => e instanceof Error
16
16
  && typeof e.constructor.TYPE === 'string';
17
17
  export class InvalidRequestError extends Error {
18
+ constructor(message) {
19
+ super(message || InvalidRequestError.TYPE);
20
+ }
18
21
  }
19
22
  InvalidRequestError.TYPE = 'InvalidRequestError';
20
23
  InvalidRequestError.matches = errorIsType(InvalidRequestError);
21
24
  export class UnauthorizedError extends Error {
25
+ constructor(message) {
26
+ super(message || UnauthorizedError.TYPE);
27
+ }
22
28
  }
23
29
  UnauthorizedError.TYPE = 'UnauthorizedError';
24
30
  UnauthorizedError.matches = errorIsType(UnauthorizedError);
25
31
  export class NotFoundError extends Error {
32
+ constructor(message) {
33
+ super(message || NotFoundError.TYPE);
34
+ }
26
35
  }
27
36
  NotFoundError.TYPE = 'NotFoundError';
28
37
  NotFoundError.matches = errorIsType(NotFoundError);
29
38
  export class SessionExpiredError extends Error {
39
+ constructor(message) {
40
+ super(message || SessionExpiredError.TYPE);
41
+ }
30
42
  }
31
43
  SessionExpiredError.TYPE = 'SessionExpiredError';
32
44
  SessionExpiredError.matches = errorIsType(SessionExpiredError);
@@ -4,8 +4,8 @@ import { Level } from '../services/logger';
4
4
  const defaultHandlers = {
5
5
  UnauthorizedError: () => apiTextResponse(401, '401 UnauthorizedError'),
6
6
  SessionExpiredError: () => apiTextResponse(440, '440 SessionExpiredError'),
7
- NotFoundError: (e) => apiTextResponse(404, e.message || '404 NotFoundError'),
8
- InvalidRequestError: (e) => apiTextResponse(400, e.message || '400 InvalidRequestError'),
7
+ NotFoundError: (e) => apiTextResponse(404, `404 ${e.message}`),
8
+ InvalidRequestError: (e) => apiTextResponse(400, `400 ${e.message}`),
9
9
  };
10
10
  export const createErrorHandler = (inputHandlers) => {
11
11
  const handlers = { ...defaultHandlers, ...inputHandlers };