mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-08-21 18:43:37 +00:00
debug-log mastodon error responses
This commit is contained in:
parent
d9d0adbc6f
commit
2aa3cf2731
2 changed files with 19 additions and 8 deletions
|
@ -46,17 +46,21 @@ export class MastodonApiServerService {
|
||||||
this.serverUtilityService.addCORS(fastify);
|
this.serverUtilityService.addCORS(fastify);
|
||||||
this.serverUtilityService.addFlattenedQueryType(fastify);
|
this.serverUtilityService.addFlattenedQueryType(fastify);
|
||||||
|
|
||||||
fastify.setErrorHandler((error, request, reply) => {
|
// Convert JS exceptions into error responses
|
||||||
try {
|
fastify.setErrorHandler((error, _, reply) => {
|
||||||
const data = getErrorData(error);
|
const data = getErrorData(error);
|
||||||
const status = getErrorStatus(error);
|
const status = getErrorStatus(error);
|
||||||
|
|
||||||
this.logger.error(request, data, status);
|
reply.code(status).send(data);
|
||||||
|
});
|
||||||
|
|
||||||
reply.code(status).send(data);
|
// Log error responses (including converted JSON exceptions)
|
||||||
} catch (e) {
|
fastify.addHook('onSend', (request, reply, payload, done) => {
|
||||||
this.logger.logger.error('Recursive error in mastodon API - this is a bug!', { e }, true);
|
if (reply.statusCode >= 400) {
|
||||||
|
const data = getErrorData(payload);
|
||||||
|
this.logger.error(request, data, reply.statusCode);
|
||||||
}
|
}
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
// External endpoints
|
// External endpoints
|
||||||
|
|
|
@ -65,6 +65,13 @@ export function getErrorData(error: unknown): MastodonError {
|
||||||
return convertGenericError(error);
|
return convertGenericError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('error' in error && typeof(error.error) === 'string') {
|
||||||
|
// "error_description" is string, undefined, or not present.
|
||||||
|
if (!('error_description' in error) || typeof(error.error_description) === 'string' || typeof(error.error_description) === 'undefined') {
|
||||||
|
return error as MastodonError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return convertUnknownError(error);
|
return convertUnknownError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue