response-standardizer 1.2.0 → 1.2.1
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.
- package/dist/index.d.ts +5 -0
- package/dist/index.js +8 -1
- package/package.json +1 -1
- package/src/index.ts +11 -1
- package/dist/service.exception.d.ts +0 -5
- package/dist/service.exception.js +0 -8
- package/src/service.exception.ts +0 -10
package/dist/index.d.ts
CHANGED
|
@@ -25,3 +25,8 @@ export declare const info: (message: string, meta?: any) => void;
|
|
|
25
25
|
export declare const log: (level: "INFO" | "WARN" | "ERROR", message: string, meta?: any) => void;
|
|
26
26
|
export declare const handleRestException: (req: Request, res: Response, err: Error) => void;
|
|
27
27
|
export declare const handleValidationException: (error: any) => never;
|
|
28
|
+
export declare class ServiceException extends Error {
|
|
29
|
+
status: number;
|
|
30
|
+
errors: any;
|
|
31
|
+
constructor(message: string, status?: number, errors?: any);
|
|
32
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { generateRequestId, getTimestamp } from "./utils.js";
|
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import jwt from "jsonwebtoken";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { ServiceException } from "./service.exception.js";
|
|
6
5
|
let KEYCLOAK_PUBLIC_KEY = null;
|
|
7
6
|
export const initKeycloak = async (config) => {
|
|
8
7
|
const KEYCLOAK_SERVICE = config.service ?? "localhost";
|
|
@@ -203,3 +202,11 @@ export const handleValidationException = (error) => {
|
|
|
203
202
|
}
|
|
204
203
|
throw new ServiceException("Internal server error", 500, error);
|
|
205
204
|
};
|
|
205
|
+
export class ServiceException extends Error {
|
|
206
|
+
constructor(message, status = 400, errors = null) {
|
|
207
|
+
super(message);
|
|
208
|
+
this.name = "ServiceException";
|
|
209
|
+
this.status = status;
|
|
210
|
+
this.errors = errors;
|
|
211
|
+
}
|
|
212
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import axios from "axios";
|
|
|
5
5
|
import jwt, { TokenExpiredError } from "jsonwebtoken";
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { ZodError } from "zod";
|
|
8
|
-
import { ServiceException } from "./service.exception.js";
|
|
9
8
|
declare global {
|
|
10
9
|
namespace Express {
|
|
11
10
|
interface Response {
|
|
@@ -259,4 +258,15 @@ export const handleValidationException = (error: any) => {
|
|
|
259
258
|
throw new ServiceException("Validation error", 400, validationErrors);
|
|
260
259
|
}
|
|
261
260
|
throw new ServiceException("Internal server error", 500, error);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export class ServiceException extends Error {
|
|
264
|
+
status: number;
|
|
265
|
+
errors: any
|
|
266
|
+
constructor(message: string, status: number = 400, errors: any = null) {
|
|
267
|
+
super(message);
|
|
268
|
+
this.name = "ServiceException";
|
|
269
|
+
this.status = status;
|
|
270
|
+
this.errors = errors;
|
|
271
|
+
}
|
|
262
272
|
}
|
package/src/service.exception.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export class ServiceException extends Error {
|
|
2
|
-
status: number;
|
|
3
|
-
errors: any
|
|
4
|
-
constructor(message: string, status: number = 400, errors: any = null) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = "ServiceException";
|
|
7
|
-
this.status = status;
|
|
8
|
-
this.errors = errors;
|
|
9
|
-
}
|
|
10
|
-
}
|