debug-log mastodon error responses
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user