tibber-express-utils 3.3.1 → 3.5.0
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/src/errors/ProblemDetailsError.d.ts +10 -4
- package/dist/src/errors/ProblemDetailsError.js +3 -2
- package/dist/src/errors/ProblemDetailsError.js.map +1 -1
- package/dist/src/jsonMiddleware.js +17 -5
- package/dist/src/jsonMiddleware.js.map +1 -1
- package/dist/src/types.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { HttpError } from './HttpError';
|
|
2
2
|
export declare type ProblemDetailsArgs = {
|
|
3
|
-
detail
|
|
4
|
-
instance
|
|
3
|
+
detail?: string;
|
|
4
|
+
instance?: string;
|
|
5
5
|
statusCode: number;
|
|
6
6
|
title: string;
|
|
7
7
|
type: string;
|
|
8
|
+
extensions?: {
|
|
9
|
+
[k: string]: unknown;
|
|
10
|
+
};
|
|
8
11
|
};
|
|
9
12
|
export declare class ProblemDetailsError extends HttpError {
|
|
10
|
-
detail: string;
|
|
11
13
|
type: string;
|
|
12
|
-
instance: string;
|
|
13
14
|
title: string;
|
|
15
|
+
detail?: string;
|
|
16
|
+
instance?: string;
|
|
17
|
+
extensions?: {
|
|
18
|
+
[k: string]: unknown;
|
|
19
|
+
};
|
|
14
20
|
constructor(args: ProblemDetailsArgs);
|
|
15
21
|
}
|
|
@@ -4,12 +4,13 @@ exports.ProblemDetailsError = void 0;
|
|
|
4
4
|
const HttpError_1 = require("./HttpError");
|
|
5
5
|
class ProblemDetailsError extends HttpError_1.HttpError {
|
|
6
6
|
constructor(args) {
|
|
7
|
-
const { detail, instance, statusCode, title, type } = args;
|
|
8
|
-
super(detail, statusCode);
|
|
7
|
+
const { detail, instance, statusCode, title, type, extensions } = args;
|
|
8
|
+
super(detail !== null && detail !== void 0 ? detail : title, statusCode);
|
|
9
9
|
this.detail = detail;
|
|
10
10
|
this.type = type;
|
|
11
11
|
this.instance = instance;
|
|
12
12
|
this.title = title;
|
|
13
|
+
this.extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
exports.ProblemDetailsError = ProblemDetailsError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProblemDetailsError.js","sourceRoot":"","sources":["../../../src/errors/ProblemDetailsError.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;
|
|
1
|
+
{"version":3,"file":"ProblemDetailsError.js","sourceRoot":"","sources":["../../../src/errors/ProblemDetailsError.ts"],"names":[],"mappings":";;;AAAA,2CAAsC;AAatC,MAAa,mBAAoB,SAAQ,qBAAS;IAShD,YAAY,IAAwB;QAClC,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAC,GAAG,IAAI,CAAC;QAErE,KAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,KAAK,EAAE,UAAU,CAAC,CAAC;QAEnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC;IACrC,CAAC;CACF;AApBD,kDAoBC"}
|
|
@@ -4,7 +4,7 @@ exports.jsonMiddleware = void 0;
|
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
5
|
const isHttpResult_1 = require("./utils/isHttpResult");
|
|
6
6
|
const jsonMiddleware = (httpStatusCodeSelector, contextSelector, handler, logger) => {
|
|
7
|
-
return async (req, res) => {
|
|
7
|
+
return async (req, res, next) => {
|
|
8
8
|
try {
|
|
9
9
|
/**
|
|
10
10
|
* Execute the RequestHandler provided against the request, extracting the context
|
|
@@ -57,26 +57,38 @@ const jsonMiddleware = (httpStatusCodeSelector, contextSelector, handler, logger
|
|
|
57
57
|
* additional details as a JSON payload.
|
|
58
58
|
*/
|
|
59
59
|
if (err instanceof errors_1.ProblemDetailsError) {
|
|
60
|
-
const { detail, httpStatus: status, instance, title, type } = err;
|
|
61
|
-
|
|
60
|
+
const { detail, httpStatus: status, instance, title, type, extensions, } = err;
|
|
61
|
+
const response = res
|
|
62
|
+
.status(status)
|
|
63
|
+
.contentType('application/problem+json')
|
|
64
|
+
.send({
|
|
65
|
+
...(extensions !== null && extensions !== void 0 ? extensions : {}),
|
|
62
66
|
detail,
|
|
63
67
|
instance,
|
|
64
68
|
status,
|
|
65
69
|
title,
|
|
66
70
|
type,
|
|
67
71
|
});
|
|
72
|
+
next(err);
|
|
73
|
+
return response;
|
|
68
74
|
}
|
|
69
75
|
/**
|
|
70
76
|
* If 'err' is a vanilla HttpError object, extract status code (defaulting to 500) and
|
|
71
77
|
* message, and send that.
|
|
72
78
|
*/
|
|
73
79
|
if (err instanceof errors_1.HttpError) {
|
|
74
|
-
|
|
80
|
+
const response = res
|
|
81
|
+
.status(err.httpStatus || 500)
|
|
82
|
+
.json({ err: err.message });
|
|
83
|
+
next(err);
|
|
84
|
+
return response;
|
|
75
85
|
}
|
|
76
86
|
/**
|
|
77
87
|
* As last resort, send error's string representation as the message.
|
|
78
88
|
*/
|
|
79
|
-
|
|
89
|
+
const response = res.status(500).send({ err: errorAsString });
|
|
90
|
+
next(err);
|
|
91
|
+
return response;
|
|
80
92
|
}
|
|
81
93
|
};
|
|
82
94
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonMiddleware.js","sourceRoot":"","sources":["../../src/jsonMiddleware.ts"],"names":[],"mappings":";;;AACA,qCAAwD;AAExD,uDAAkD;AAE3C,MAAM,cAAc,GAAmB,CAC5C,sBAAsB,EACtB,eAAe,EACf,OAAO,EACP,MAAM,EACN,EAAE;IACF,OAAO,KAAK,EAAE,GAAY,EAAE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Ac,kBA0GzB"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Request, Response, Router } from 'express';
|
|
1
|
+
import { NextFunction, Request, Response, Router } from 'express';
|
|
2
2
|
import { PathParams } from 'express-serve-static-core';
|
|
3
3
|
import { HttpResult } from './HttpResult';
|
|
4
4
|
/**
|
|
@@ -78,7 +78,7 @@ export interface Logger {
|
|
|
78
78
|
* request handling.
|
|
79
79
|
*/
|
|
80
80
|
export declare type JsonMiddleware = {
|
|
81
|
-
<TContext, TPayload>(httpStatusCodeSelector: HttpStatusCodeSelector, contextSelector: ContextSelector<TContext>, handler: JsonRequestHandler<TContext, TPayload>, logger?: Logger): (req: Request, res: Response) => Promise<Response<TPayload>>;
|
|
81
|
+
<TContext, TPayload>(httpStatusCodeSelector: HttpStatusCodeSelector, contextSelector: ContextSelector<TContext>, handler: JsonRequestHandler<TContext, TPayload>, logger?: Logger): (req: Request, res: Response, next: NextFunction) => Promise<Response<TPayload>>;
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
84
|
* Defines logic remapping a status code returned from a JsonRequestHandler in a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tibber-express-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"clean": "gts clean",
|
|
11
11
|
"compile": "tsc",
|
|
12
12
|
"fix": "gts fix && sortier \"./**/*.{ts,tsx,js,jsx}\"",
|
|
13
|
-
"prepare": "yarn run compile",
|
|
13
|
+
"prepare": "yarn run compile && husky install",
|
|
14
14
|
"pretest": "yarn run compile",
|
|
15
15
|
"posttest": "yarn run lint",
|
|
16
16
|
"release": "semantic-release",
|