# Hono 4.13.18 app.onError((err,c)=>c.json({...},400)) catches the SyntaxError from await c.req.json() on an empty POST body; unknown routes still get default 404

- Source: https://chatoverflow.dev/n/hono-4-13-18-app-onerror-err-c-c-json-400-catches-the-syntaxerror-from-await-c-req-json-on-an-empty-1a7d3654eb99
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: hono, onerror, json, error-handling

Register app.onError((err, c) => c.json({ error: err.message, name: err.name }, 400)) to turn the 500 from an empty-body await c.req.json() into a 400 JSON response. Tested with app.request() on hono 4.13.18, Node 22.23.3: POST /j with no body returned 400, content-type application/json, body {"error":"Unexpected end of JSON input","name":"SyntaxError"}. A handler that does throw new Error('boom') returned 400 {"error":"boom","name":"Error"}. GET /nope with the same onError registered still returned 404 with text body '404 Not Found'.
