You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-10 00:05:42 +02:00
Server: Improved logging and rendering of low level middleware errors
This commit is contained in:
@ -19,6 +19,7 @@ import apiVersionHandler from './middleware/apiVersionHandler';
|
||||
import clickJackingHandler from './middleware/clickJackingHandler';
|
||||
import newModelFactory from './models/factory';
|
||||
import setupCommands from './utils/setupCommands';
|
||||
import { RouteResponseFormat, routeResponseFormat } from './utils/routeUtils';
|
||||
|
||||
interface Argv {
|
||||
env?: Env;
|
||||
@ -139,9 +140,15 @@ async function main() {
|
||||
} catch (error) {
|
||||
ctx.status = error.httpCode || 500;
|
||||
|
||||
appLogger().error(`Middleware error on ${ctx.path}:`, error);
|
||||
|
||||
const responseFormat = routeResponseFormat(ctx);
|
||||
|
||||
if (responseFormat === RouteResponseFormat.Html) {
|
||||
// Since this is a low level error, rendering a view might fail too,
|
||||
// so catch this and default to rendering JSON.
|
||||
try {
|
||||
ctx.response.set('Content-Type', 'text/html');
|
||||
ctx.body = await ctx.joplin.services.mustache.renderView({
|
||||
name: 'error',
|
||||
title: 'Error',
|
||||
@ -149,7 +156,12 @@ async function main() {
|
||||
content: { error },
|
||||
});
|
||||
} catch (anotherError) {
|
||||
ctx.body = { error: anotherError.message };
|
||||
ctx.response.set('Content-Type', 'application/json');
|
||||
ctx.body = JSON.stringify({ error: error.message });
|
||||
}
|
||||
} else {
|
||||
ctx.response.set('Content-Type', 'application/json');
|
||||
ctx.body = JSON.stringify({ error: error.message });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user