@okay-e9g/hono-config 0.0.17 → 0.0.18
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/package.json +1 -1
- package/src/handlers/on-error.ts +7 -9
package/package.json
CHANGED
package/src/handlers/on-error.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { ResponseEnv } from '../middlewares/ensure-rt';
|
|
|
10
10
|
import { type ClientErrorStatusCode, rpcStandardErrorText, type ServerErrorStatusCode } from '../schemas';
|
|
11
11
|
|
|
12
12
|
interface TypedHTTPException extends Omit<HTTPException, 'status'> {
|
|
13
|
-
status: ClientErrorStatusCode
|
|
13
|
+
status: ClientErrorStatusCode | ServerErrorStatusCode;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const assertHTTPException = (err: Error): err is TypedHTTPException => {
|
|
@@ -23,8 +23,9 @@ const assertHTTPException = (err: Error): err is TypedHTTPException => {
|
|
|
23
23
|
* Errors are rethrown when no response helper has been installed, allowing
|
|
24
24
|
* Hono's fallback error handling to handle apps that are not using this
|
|
25
25
|
* package's response envelopes. API helpers preserve HTTP error semantics.
|
|
26
|
-
* RPC helpers map validation failures to `Invalid Params
|
|
27
|
-
*
|
|
26
|
+
* RPC helpers map validation failures to `Invalid Params`, 4xx HTTP exceptions
|
|
27
|
+
* to `Invalid Request`, and 5xx or generic failures to `Internal Error`,
|
|
28
|
+
* returning a JSON-RPC envelope with a `null` id.
|
|
28
29
|
*
|
|
29
30
|
* @internal
|
|
30
31
|
*/
|
|
@@ -57,12 +58,9 @@ export const onError = <T extends Env>(): ErrorHandler<T> => {
|
|
|
57
58
|
return c.json(response.error(status, message), status);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
message: message === '' ? rpcStandardErrorText['-32603'] : message,
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
61
|
+
const code = status < 500 ? -32600 : -32603;
|
|
62
|
+
|
|
63
|
+
return c.json(response.error({ code, message: message === '' ? rpcStandardErrorText[code] : message }));
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
const errMessage = err instanceof Error ? err.message : err;
|