shelving 1.150.0 → 1.150.2
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/api/Endpoint.js +4 -2
- package/package.json +1 -1
- package/util/http.js +5 -2
package/api/Endpoint.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getResponse } from "../util/http.js";
|
|
2
|
-
import { UNDEFINED } from "../util/validate.js";
|
|
2
|
+
import { UNDEFINED, getValid } from "../util/validate.js";
|
|
3
3
|
/**
|
|
4
4
|
* An abstract API resource definition, used to specify types for e.g. serverless functions.
|
|
5
5
|
*
|
|
@@ -42,7 +42,9 @@ export class Endpoint {
|
|
|
42
42
|
// Validate the payload against this endpoint's payload type.
|
|
43
43
|
const payload = this.payload.validate(unsafePayload);
|
|
44
44
|
// Call the callback with the validated payload to get the result.
|
|
45
|
-
const
|
|
45
|
+
const unsafeResult = await callback(payload, request);
|
|
46
|
+
// Validate the result against this endpoint's result type.
|
|
47
|
+
const result = getValid(unsafeResult, this.result);
|
|
46
48
|
// Convert the result to a `Response` object.
|
|
47
49
|
return getResponse(result);
|
|
48
50
|
}
|
package/package.json
CHANGED
package/util/http.js
CHANGED
|
@@ -117,8 +117,11 @@ export function getErrorResponse(reason, debug = false) {
|
|
|
117
117
|
// Throw `RequestError` to set a custom status code (e.g. `UnauthorizedError`).
|
|
118
118
|
const status = reason instanceof RequestError ? reason.code : 500;
|
|
119
119
|
// Throw `Error` to return `{ message: "etc" }` to the client (but only if `debug` is true so we don't leak error details to the client).
|
|
120
|
-
if (debug && isError(reason))
|
|
121
|
-
|
|
120
|
+
if (debug && isError(reason)) {
|
|
121
|
+
// Manually destructure because `Error.prototype.message` is not enumerable.
|
|
122
|
+
const { message, ...rest } = reason;
|
|
123
|
+
return Response.json({ message, ...rest }, { status });
|
|
124
|
+
}
|
|
122
125
|
// Otherwise return a generic error message with no details.
|
|
123
126
|
return new Response(undefined, { status });
|
|
124
127
|
}
|