fix(export): surface checkValidRev error message on bad :rev#7792
Conversation
A non-numeric :rev (e.g. /p/foo/test1/export/txt) was reaching
checkValidRev, which throws CustomError('rev is not a number',
'apierror'). The error fell through the route handler's
.catch(next), so Express's default error renderer kicked in and
returned a 500 with the generic HTML page <title>Error</title> /
<pre>Internal Server Error</pre>. The thrown message never made it
to the body, so callers had no way to tell why the request failed.
Catch the apierror in the route handler and send err.message as a
text/plain 500 body. Other errors still propagate to next(err) so
unrelated failures keep their existing handling.
Also retitle the test (was "is 403" while asserting expect(500)) —
leftover label from an earlier expectation.
Fixes #7788
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Review Summary by QodoSurface checkValidRev error message in export response body
WalkthroughsDescription• Surface checkValidRev error message in export response body • Non-numeric :rev parameter now returns plain-text 500 with error message • Prevents Express default HTML error page from being returned • Retitle test to accurately reflect expected 500 status code Diagramflowchart LR
A["Non-numeric :rev parameter"] -->|"checkValidRev throws apierror"| B["Route handler catches error"]
B -->|"err.name === apierror"| C["Send text/plain 500 with message"]
B -->|"other errors"| D["Propagate to Express handler"]
File Changes1. src/node/hooks/express/importexport.ts
|
Code Review by Qodo
1.
|
Qodo feedback on #7792: 1) ExportHandler.doExport set Content-Disposition (via res.attachment) before calling checkValidRev. If the rev was invalid, the route-level catch returned a plain-text 500 — but the attachment header was still in place, so browsers offered to save the error message as a file. Move checkValidRev to the top of doExport so an invalid rev never touches the attachment header. 2) The catch only converted CustomError('...', 'apierror') into a plain-text response. Other export errors (conversion failures, fs issues, soffice problems) still fell through to Express's default HTML renderer — non-deterministic for API callers and confusing when they were already half-downloading a file. Surface every export failure as a deterministic text/plain 500. apierrors carry user-facing messages, so send err.message verbatim. For other errors, log the full stack server-side and still emit err.message (or 'Internal Server Error' if absent) so the response body is never the Express HTML stack page. Also clear Content-Disposition in the catch as a safety net. Backend tests (importexportGetPost.ts): 58 passing, 0 failing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
/p/:pad/:rev/export/:typewith a non-numeric:rev(e.g.test1) was returning a 500 with Express's default HTML error page (<title>Error</title>…<pre>Internal Server Error</pre>).checkValidRevdoes throw aCustomError('rev is not a number', 'apierror'), but the route handler's.catch(next)handed the error to Express's default renderer and the message never reached the body. Callers had no way to tell why the export failed.Catch the apierror in the route handler and send the message as a text/plain 500 body. All other error names still go through
next(err)so we don't change behaviour for unrelated failures.Also retitle the two affected tests — they said "is 403" while asserting
expect(500), a leftover from an earlier expectation.Test plan
tests/backend/specs/api/importexportGetPost.ts:txt request rev test1,html request rev test1).The fix is narrow: it only intercepts errors whose
name === 'apierror'. Anything else continues to propagate to Express's error handler.Note: these failures are invisible in CI today because of the broken backend test glob — see #7789. That has to land for the green checks on this PR to actually run the affected tests.
Fixes #7788
🤖 Generated with Claude Code