@aeriajs/http 0.0.67 → 0.0.69
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/routing.js +7 -8
- package/dist/routing.mjs +14 -15
- package/package.json +5 -5
package/dist/routing.js
CHANGED
|
@@ -8,19 +8,18 @@ const validation_1 = require("@aeriajs/validation");
|
|
|
8
8
|
const entrypoint_1 = require("@aeriajs/entrypoint");
|
|
9
9
|
const payload_js_1 = require("./payload.js");
|
|
10
10
|
const next_js_1 = require("./next.js");
|
|
11
|
-
const checkUnprocessable = (
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
if ('code' in validationError) {
|
|
11
|
+
const checkUnprocessable = ({ error }, context) => {
|
|
12
|
+
if (error) {
|
|
13
|
+
if ('code' in error) {
|
|
15
14
|
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
16
|
-
code:
|
|
17
|
-
details:
|
|
15
|
+
code: error.code,
|
|
16
|
+
details: error.errors,
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
21
20
|
code: 'UNPROCESSABLE_ENTITY',
|
|
22
21
|
message: 'the provided payload is unprocessable',
|
|
23
|
-
details:
|
|
22
|
+
details: error,
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
25
|
};
|
|
@@ -131,7 +130,7 @@ const wrapRouteExecution = async (response, cb) => {
|
|
|
131
130
|
response.writeHead(500);
|
|
132
131
|
}
|
|
133
132
|
if (!response.writableEnded) {
|
|
134
|
-
return (0, common_1.
|
|
133
|
+
return (0, common_1.endpointError)({
|
|
135
134
|
httpStatus: 500,
|
|
136
135
|
code: 'UNKNOWN_ERROR',
|
|
137
136
|
message: 'Internal server error',
|
package/dist/routing.mjs
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Stream } from "stream";
|
|
3
3
|
import { ACError, HTTPStatus, REQUEST_METHODS } from "@aeriajs/types";
|
|
4
|
-
import { pipe, isGranted,
|
|
4
|
+
import { pipe, isGranted, deepMerge, endpointError } from "@aeriajs/common";
|
|
5
5
|
import { validate } from "@aeriajs/validation";
|
|
6
6
|
import { getConfig } from "@aeriajs/entrypoint";
|
|
7
7
|
import { safeJson } from "./payload.mjs";
|
|
8
8
|
import { isNext } from "./next.mjs";
|
|
9
|
-
const checkUnprocessable = (
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
if ("code" in validationError) {
|
|
9
|
+
const checkUnprocessable = ({ error }, context) => {
|
|
10
|
+
if (error) {
|
|
11
|
+
if ("code" in error) {
|
|
13
12
|
return context.error(HTTPStatus.UnprocessableContent, {
|
|
14
|
-
code:
|
|
15
|
-
details:
|
|
13
|
+
code: error.code,
|
|
14
|
+
details: error.errors
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
17
|
return context.error(HTTPStatus.UnprocessableContent, {
|
|
19
18
|
code: "UNPROCESSABLE_ENTITY",
|
|
20
19
|
message: "the provided payload is unprocessable",
|
|
21
|
-
details:
|
|
20
|
+
details: error
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
23
|
};
|
|
@@ -78,18 +77,18 @@ export const registerRoute = async (context, method, exp, cb, contract, options
|
|
|
78
77
|
}
|
|
79
78
|
if ("payload" in contract && contract.payload) {
|
|
80
79
|
const validationEither = validate(context.request.payload, contract.payload);
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
return
|
|
80
|
+
const error = checkUnprocessable(validationEither, context);
|
|
81
|
+
if (error) {
|
|
82
|
+
return error;
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
if ("query" in contract && contract.query) {
|
|
87
86
|
const validationEither = validate(context.request.query, contract.query, {
|
|
88
87
|
coerce: true
|
|
89
88
|
});
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
89
|
+
const error = checkUnprocessable(validationEither, context);
|
|
90
|
+
if (error) {
|
|
91
|
+
return error;
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
}
|
|
@@ -124,7 +123,7 @@ export const wrapRouteExecution = async (response, cb) => {
|
|
|
124
123
|
response.writeHead(500);
|
|
125
124
|
}
|
|
126
125
|
if (!response.writableEnded) {
|
|
127
|
-
return
|
|
126
|
+
return endpointError({
|
|
128
127
|
httpStatus: 500,
|
|
129
128
|
code: "UNKNOWN_ERROR",
|
|
130
129
|
message: "Internal server error"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.69",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"@aeriajs/validation": "link:../validation"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@aeriajs/common": "^0.0.
|
|
32
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
33
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
-
"@aeriajs/validation": "^0.0.
|
|
31
|
+
"@aeriajs/common": "^0.0.60",
|
|
32
|
+
"@aeriajs/entrypoint": "^0.0.61",
|
|
33
|
+
"@aeriajs/types": "^0.0.56",
|
|
34
|
+
"@aeriajs/validation": "^0.0.63"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "echo skipping",
|