Better (more private...) error handling

This commit is contained in:
2026-03-13 12:01:13 +01:00
parent 69fc7235c6
commit 4b9b5b737d
2 changed files with 22 additions and 5 deletions

View File

@@ -18,7 +18,7 @@ router.get('/iiif/:manifestid/manifest', async function(req, res) {
res.status(500).json({ res.status(500).json({
status: 500, status: 500,
message: 'There was an error processing this request', message: 'There was an error processing this request',
details: error code: error.code ?? 'not available',
}); });
} }
res.json(manifest); res.json(manifest);
@@ -31,7 +31,11 @@ router.get('/iiif/:manifestid/canvas/:name', async function(req, res) {
try { try {
canvas = await generateCanvas(req.params.manifestid, req.params.name) canvas = await generateCanvas(req.params.manifestid, req.params.name)
} catch(error) { } 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; return;
} }
res.json(canvas); res.json(canvas);
@@ -44,7 +48,11 @@ router.get('/iiif/:manifestid/sequence/:name', async function(req, res) {
try { try {
sequence = await generateSequence(req.params.manifestid, req.params.name) sequence = await generateSequence(req.params.manifestid, req.params.name)
} catch(error) { } 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); res.json(sequence);
}); });
@@ -55,7 +63,11 @@ router.get('/params', async function(req, res) {
try { try {
res.json(await exposeParams()); res.json(await exposeParams());
} catch(error) { } 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',
});
} }
}); });

View File

@@ -1,12 +1,15 @@
'use strict'; 'use strict';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path';
import Manifest from './Manifest.js'; import Manifest from './Manifest.js';
import Sequence from './Sequence.js'; import Sequence from './Sequence.js';
import Canvas from './Canvas.js'; import Canvas from './Canvas.js';
import Image from './Image.js'; import Image from './Image.js';
import ManifestMetadata from './Metadata.js'; import ManifestMetadata from './Metadata.js';
/**
* @namespace Common
*/
const Common = {}; const Common = {};
const authors = { const authors = {
@@ -103,6 +106,8 @@ Common.getParamsFromFolders = async function() {
/** /**
* @param {string} manifestId * @param {string} manifestId
* @returns {string[]} * @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) { Common.getImageList = async function (manifestId) {
// Regex to exclude images with certain patterns in filename // Regex to exclude images with certain patterns in filename