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 clickJackingHandler from './middleware/clickJackingHandler';
|
||||||
import newModelFactory from './models/factory';
|
import newModelFactory from './models/factory';
|
||||||
import setupCommands from './utils/setupCommands';
|
import setupCommands from './utils/setupCommands';
|
||||||
|
import { RouteResponseFormat, routeResponseFormat } from './utils/routeUtils';
|
||||||
|
|
||||||
interface Argv {
|
interface Argv {
|
||||||
env?: Env;
|
env?: Env;
|
||||||
@ -139,17 +140,28 @@ async function main() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
ctx.status = error.httpCode || 500;
|
ctx.status = error.httpCode || 500;
|
||||||
|
|
||||||
// Since this is a low level error, rendering a view might fail too,
|
appLogger().error(`Middleware error on ${ctx.path}:`, error);
|
||||||
// so catch this and default to rendering JSON.
|
|
||||||
try {
|
const responseFormat = routeResponseFormat(ctx);
|
||||||
ctx.body = await ctx.joplin.services.mustache.renderView({
|
|
||||||
name: 'error',
|
if (responseFormat === RouteResponseFormat.Html) {
|
||||||
title: 'Error',
|
// Since this is a low level error, rendering a view might fail too,
|
||||||
path: 'index/error',
|
// so catch this and default to rendering JSON.
|
||||||
content: { error },
|
try {
|
||||||
});
|
ctx.response.set('Content-Type', 'text/html');
|
||||||
} catch (anotherError) {
|
ctx.body = await ctx.joplin.services.mustache.renderView({
|
||||||
ctx.body = { error: anotherError.message };
|
name: 'error',
|
||||||
|
title: 'Error',
|
||||||
|
path: 'index/error',
|
||||||
|
content: { error },
|
||||||
|
});
|
||||||
|
} catch (anotherError) {
|
||||||
|
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