@nr1e/commons 0.0.2-alpha.3 → 0.0.2-alpha.4

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,9 +6,9 @@ interface IError {
6
6
  statusCode?: HttpStatusCode | number;
7
7
  }
8
8
  /**
9
- * Checks if the given variable is a NotFoundError.
9
+ * Checks if the given parameter is a NotFoundError.
10
10
  *
11
- * @param e the variable to check
11
+ * @param e the parameter to check
12
12
  */
13
13
  export declare function isNotFoundError(e?: IError | null): e is NotFoundError;
14
14
  /**
@@ -19,9 +19,9 @@ export declare class NotFoundError extends Error {
19
19
  constructor(message?: string);
20
20
  }
21
21
  /**
22
- * Checks if the given variable is a ForbiddenError.
22
+ * Checks if the given parameter is a ForbiddenError.
23
23
  *
24
- * @param e the variable to check
24
+ * @param e the parameter to check
25
25
  */
26
26
  export declare function isForbiddenError(e?: IError | null): e is ForbiddenError;
27
27
  /**
@@ -44,4 +44,30 @@ export declare class ValidationError extends Error {
44
44
  readonly statusCode = HttpStatusCode.BAD_REQUEST;
45
45
  constructor(message?: string);
46
46
  }
47
+ /**
48
+ * Checks if the given parameter is a BadRequestError.
49
+ *
50
+ * @param e the parameter to check
51
+ */
52
+ export declare function isBadRequestError(e?: IError | null): e is BadRequestError;
53
+ /**
54
+ * Thrown when a bad request is made.
55
+ */
56
+ export declare class BadRequestError extends Error {
57
+ readonly statusCode = HttpStatusCode.BAD_REQUEST;
58
+ constructor(message?: string);
59
+ }
60
+ /**
61
+ * Checks if the given parameter is a InternalServerError.
62
+ *
63
+ * @param e the parameter to check
64
+ */
65
+ export declare function isInternalServerError(e?: IError | null): e is InternalServerError;
66
+ /**
67
+ * Throws when an internal server error occurs.
68
+ */
69
+ export declare class InternalServerError extends Error {
70
+ readonly statusCode = HttpStatusCode.INTERNAL_ERROR;
71
+ constructor(message?: string);
72
+ }
47
73
  export {};
package/errors/errors.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = void 0;
3
+ exports.InternalServerError = exports.isInternalServerError = exports.BadRequestError = exports.isBadRequestError = exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = void 0;
4
4
  const http_1 = require("../http");
5
5
  /**
6
- * Checks if the given variable is a NotFoundError.
6
+ * Checks if the given parameter is a NotFoundError.
7
7
  *
8
- * @param e the variable to check
8
+ * @param e the parameter to check
9
9
  */
10
10
  function isNotFoundError(e) {
11
11
  return !!(e &&
@@ -28,9 +28,9 @@ class NotFoundError extends Error {
28
28
  }
29
29
  exports.NotFoundError = NotFoundError;
30
30
  /**
31
- * Checks if the given variable is a ForbiddenError.
31
+ * Checks if the given parameter is a ForbiddenError.
32
32
  *
33
- * @param e the variable to check
33
+ * @param e the parameter to check
34
34
  */
35
35
  function isForbiddenError(e) {
36
36
  return !!(e &&
@@ -76,4 +76,52 @@ class ValidationError extends Error {
76
76
  }
77
77
  }
78
78
  exports.ValidationError = ValidationError;
79
+ /**
80
+ * Checks if the given parameter is a BadRequestError.
81
+ *
82
+ * @param e the parameter to check
83
+ */
84
+ function isBadRequestError(e) {
85
+ return !!(e &&
86
+ e.stack &&
87
+ e.message &&
88
+ e.statusCode &&
89
+ e.name === 'BadRequestError');
90
+ }
91
+ exports.isBadRequestError = isBadRequestError;
92
+ /**
93
+ * Thrown when a bad request is made.
94
+ */
95
+ class BadRequestError extends Error {
96
+ constructor(message) {
97
+ super(message !== null && message !== void 0 ? message : 'Bad request');
98
+ this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
99
+ this.name = 'BadRequestError';
100
+ }
101
+ }
102
+ exports.BadRequestError = BadRequestError;
103
+ /**
104
+ * Checks if the given parameter is a InternalServerError.
105
+ *
106
+ * @param e the parameter to check
107
+ */
108
+ function isInternalServerError(e) {
109
+ return !!(e &&
110
+ e.stack &&
111
+ e.message &&
112
+ e.statusCode &&
113
+ e.name === 'InternalServerError');
114
+ }
115
+ exports.isInternalServerError = isInternalServerError;
116
+ /**
117
+ * Throws when an internal server error occurs.
118
+ */
119
+ class InternalServerError extends Error {
120
+ constructor(message) {
121
+ super(message !== null && message !== void 0 ? message : 'Internal server error');
122
+ this.statusCode = http_1.HttpStatusCode.INTERNAL_ERROR;
123
+ this.name = 'InternalServerError';
124
+ }
125
+ }
126
+ exports.InternalServerError = InternalServerError;
79
127
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;AASvC;;;;GAIG;AACH,SAAgB,eAAe,CAAC,CAAiB;IAC/C,OAAO,CAAC,CAAC,CACP,CAAC;QACD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,IAAI,KAAK,eAAe,CAC3B,CAAC;AACJ,CAAC;AATD,0CASC;AAED;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IAGtC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,WAAW,CAAC,CAAC;QAHvB,eAAU,GAAG,qBAAc,CAAC,SAAS,CAAC;QAI7C,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAPD,sCAOC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,CAAiB;IAChD,OAAO,CAAC,CAAC,CACP,CAAC;QACD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAC5B,CAAC;AACJ,CAAC;AATD,4CASC;AAED;;GAEG;AACH,MAAa,cAAe,SAAQ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AK,iBAAiB,CAC7B,CAAC;AACJ,CAAC;AARD,8CAQC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IAGxC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,aAAa,CAAC,CAAC;QAHzB,eAAU,GAAG,qBAAc,CAAC,WAAW,CAAC;QAI/C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAPD,0CAOC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CACnC,CAAiB;IAEjB,OAAO,CAAC,CAAC,CACP,CAAC;QACD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,IAAI,KAAK,qBAAqB,CACjC,CAAC;AACJ,CAAC;AAVD,sDAUC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAG5C,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,uBAAuB,CAAC,CAAC;QAHnC,eAAU,GAAG,qBAAc,CAAC,cAAc,CAAC;QAIlD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAPD,kDAOC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nr1e/commons",
3
3
  "description": "Provides common patterns for validation",
4
- "version": "0.0.2-alpha.3",
4
+ "version": "0.0.2-alpha.4",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "author": "NR1E, Inc.",