From 4b9b5b737dc6ed323b5aff76d7f9ab9be10f334f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Fri, 13 Mar 2026 12:01:13 +0100 Subject: [PATCH] Better (more private...) error handling --- routes/index.mjs | 20 ++++++++++++++++---- src/common.js | 7 ++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/routes/index.mjs b/routes/index.mjs index 4b9edba..fc7af80 100644 --- a/routes/index.mjs +++ b/routes/index.mjs @@ -18,7 +18,7 @@ router.get('/iiif/:manifestid/manifest', async function(req, res) { res.status(500).json({ status: 500, message: 'There was an error processing this request', - details: error + code: error.code ?? 'not available', }); } res.json(manifest); @@ -31,7 +31,11 @@ router.get('/iiif/:manifestid/canvas/:name', async function(req, res) { try { canvas = await generateCanvas(req.params.manifestid, req.params.name) } catch(error) { - res.status(500).json({status: 500, message: 'There was an error processing this request: ' + error}); + res.status(500).json({ + status: 500, + message: 'There was an error processing this request', + code: error.code ?? 'not available', + }); return; } res.json(canvas); @@ -44,7 +48,11 @@ router.get('/iiif/:manifestid/sequence/:name', async function(req, res) { try { sequence = await generateSequence(req.params.manifestid, req.params.name) } catch(error) { - res.status(500).json({status: 500, message: 'There was an error processing this request'}); + res.status(500).json({ + status: 500, + message: 'There was an error processing this request', + code: error.code ?? 'not available', + }); } res.json(sequence); }); @@ -55,7 +63,11 @@ router.get('/params', async function(req, res) { try { res.json(await exposeParams()); } catch(error) { - res.status(500).json({status: 500, message: 'There was an error processing this request'}); + res.status(500).json({ + status: 500, + message: 'There was an error processing this request', + code: error.code ?? 'not available', + }); } }); diff --git a/src/common.js b/src/common.js index 6031a8d..be5f479 100644 --- a/src/common.js +++ b/src/common.js @@ -1,12 +1,15 @@ 'use strict'; import * as fs from 'fs'; -import * as path from 'path'; import Manifest from './Manifest.js'; import Sequence from './Sequence.js'; import Canvas from './Canvas.js'; import Image from './Image.js'; import ManifestMetadata from './Metadata.js'; + +/** + * @namespace Common + */ const Common = {}; const authors = { @@ -103,6 +106,8 @@ Common.getParamsFromFolders = async function() { /** * @param {string} manifestId * @returns {string[]} + * @throws `readdir` will thrown an ENOENT error if the images folder doesn't exist. + * The manifest route should catch it. */ Common.getImageList = async function (manifestId) { // Regex to exclude images with certain patterns in filename