From bd0a39f4fb95509d27bfea7ad4908e6e67ae19ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB?= Date: Mon, 15 Jul 2024 15:11:29 +0100 Subject: [PATCH] Handles remote 4xx and 5xx responses and logs them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At present if the remote service returns an error, we get an undifferentiated 500 back from zotero. This means we cannot distinguish between a 403, a 404 or a 500 – and so we cannot easily debug why specific sites are giving our upstream citoid server issues. Change-Id: I6db4f3f7f8b2813a6c9ff09061379a7cec17cea7 --- src/webSession.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/webSession.js b/src/webSession.js index 47c50b0..4b63761 100644 --- a/src/webSession.js +++ b/src/webSession.js @@ -216,6 +216,11 @@ WebSession.prototype.handleURL = async function () { // No more URLs to try if (i == urlsToTry.length - 1) { + if (e instanceof Zotero.HTTP.StatusError && e.status >= 400 && e.status < 500) { + this.ctx.throw(503, `Remote server could not provide document (${e.status})`); + } else if (e instanceof Zotero.HTTP.StatusError && e.status >= 500) { + this.ctx.throw(503, `Remote server encountered an error handling our request (${e.status})`); + } this.ctx.throw(500, "An error occurred retrieving the document"); } }