From fc40c1f8a42b37d759c14db5185af2d4c9fc0a65 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 22 Jul 2026 16:53:08 +0200 Subject: [PATCH] Merge pull request #35636 from overleaf/tm-fix-export-error-forwarding [web] Forward v1 export errors to the publish modal instead of a 500 GitOrigin-RevId: 7cf69c4d6a954cd311ac64fff175156b300afabb --- .../web/app/src/Features/Exports/ExportsHandler.mjs | 8 +++++++- .../test/unit/src/Exports/ExportsHandler.test.mjs | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/web/app/src/Features/Exports/ExportsHandler.mjs b/services/web/app/src/Features/Exports/ExportsHandler.mjs index 2f12dea115..704778db71 100644 --- a/services/web/app/src/Features/Exports/ExportsHandler.mjs +++ b/services/web/app/src/Features/Exports/ExportsHandler.mjs @@ -133,9 +133,15 @@ export default ExportsHandler = { { export: exportData }, `v1 export returned failure; forwarding: ${err.body}` ) + let forwardResponse + try { + forwardResponse = JSON.parse(err.body) + } catch (parseError) { + forwardResponse = { status: err.response.status, message: err.body } + } // pass the v1 error along for the publish modal to handle throw OError.tag(err, 'v1 export returned failure', { - forwardResponse: err.body, + forwardResponse, }) } throw OError.tag(err, 'error making request to v1 export', { diff --git a/services/web/test/unit/src/Exports/ExportsHandler.test.mjs b/services/web/test/unit/src/Exports/ExportsHandler.test.mjs index e8842f7df7..678daf812e 100644 --- a/services/web/test/unit/src/Exports/ExportsHandler.test.mjs +++ b/services/web/test/unit/src/Exports/ExportsHandler.test.mjs @@ -513,6 +513,7 @@ describe('ExportsHandler', function () { beforeEach(async function (ctx) { ctx.error_code = 422 ctx.error_json = { status: ctx.error_code, message: 'nope' } + // fetch-utils exposes the response body as a string, not a parsed object ctx.fetchUtils.fetchJson = sinon .stub() .rejects( @@ -520,7 +521,7 @@ describe('ExportsHandler', function () { new URL('/api/v1/overleaf/exports', ctx.settings.apis.v1.url), {}, { status: ctx.error_code }, - ctx.error_json + JSON.stringify(ctx.error_json) ) ) @@ -531,12 +532,11 @@ describe('ExportsHandler', function () { } }) - it('should throw with an error containing the response to forward', function (ctx) { + it('should throw with an error containing the parsed response to forward', function (ctx) { expect(response).to.be.undefined - expect(OError.getFullInfo(error)).to.have.property( - 'forwardResponse', - ctx.error_json - ) + expect(OError.getFullInfo(error)) + .to.have.property('forwardResponse') + .that.deep.equals(ctx.error_json) }) }) })