Skip to content

Commit eaa9575

Browse files
committed
add error test
1 parent 104476b commit eaa9575

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/hono/src/honoPlugin.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,19 @@ describe("basic routing", () => {
170170
describe("hono passthrough", () => {
171171
const baseApi = stl.api({
172172
basePath: "/api",
173-
resources: {},
173+
resources: {
174+
posts: stl.resource({
175+
summary: "posts",
176+
actions: {
177+
retrieve: stl.endpoint({
178+
endpoint: "GET /api/posts",
179+
handler: () => {
180+
throw new Error("arbitrary error");
181+
},
182+
}),
183+
},
184+
}),
185+
},
174186
});
175187

176188
const app = new Hono();
@@ -181,6 +193,9 @@ describe("hono passthrough", () => {
181193
app.notFound((c) => {
182194
return c.text("custom not found", 404);
183195
});
196+
app.onError((err, c) => {
197+
return c.text(`custom error: ${err.message}`, 500);
198+
});
184199

185200
test("public passthrough", async () => {
186201
const response = await app.request("/public/foo/bar");
@@ -193,4 +208,12 @@ describe("hono passthrough", () => {
193208
expect(response).toHaveProperty("status", 404);
194209
expect(await response.text()).toMatchInlineSnapshot(`"custom not found"`);
195210
});
211+
212+
test("error passthrough", async () => {
213+
const response = await app.request("/api/posts");
214+
expect(response).toHaveProperty("status", 500);
215+
expect(await response.text()).toMatchInlineSnapshot(
216+
`"custom error: arbitrary error"`
217+
);
218+
});
196219
});

0 commit comments

Comments
 (0)