mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
more fixes to Mastodon logging
This commit is contained in:
parent
b6f4fda80d
commit
9db39d449f
2 changed files with 8 additions and 19 deletions
|
@ -51,6 +51,7 @@ export class MastodonApiServerService {
|
||||||
const data = getErrorData(error);
|
const data = getErrorData(error);
|
||||||
const status = getErrorStatus(error);
|
const status = getErrorStatus(error);
|
||||||
const exception = getErrorException(error);
|
const exception = getErrorException(error);
|
||||||
|
|
||||||
if (exception) {
|
if (exception) {
|
||||||
this.logger.exception(request, exception);
|
this.logger.exception(request, exception);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +61,7 @@ export class MastodonApiServerService {
|
||||||
|
|
||||||
// Log error responses (including converted JSON exceptions)
|
// Log error responses (including converted JSON exceptions)
|
||||||
fastify.addHook('onSend', (request, reply, payload, done) => {
|
fastify.addHook('onSend', (request, reply, payload, done) => {
|
||||||
if (reply.statusCode >= 400 && reply.statusCode <= 500) {
|
if (reply.statusCode >= 400) {
|
||||||
if (typeof(payload) === 'string' && String(reply.getHeader('content-type')).toLowerCase().includes('application/json')) {
|
if (typeof(payload) === 'string' && String(reply.getHeader('content-type')).toLowerCase().includes('application/json')) {
|
||||||
const body = JSON.parse(payload);
|
const body = JSON.parse(payload);
|
||||||
const data = getErrorData(body);
|
const data = getErrorData(body);
|
||||||
|
|
|
@ -14,10 +14,6 @@ import { getBaseUrl } from '@/server/api/mastodon/MastodonClientService.js';
|
||||||
export class MastodonLogger {
|
export class MastodonLogger {
|
||||||
public readonly logger: Logger;
|
public readonly logger: Logger;
|
||||||
|
|
||||||
public get verbose() {
|
|
||||||
return this.logger.verbose;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
loggerService: LoggerService,
|
loggerService: LoggerService,
|
||||||
) {
|
) {
|
||||||
|
@ -65,13 +61,12 @@ export function getErrorException(error: unknown): Error | null {
|
||||||
return error.cause;
|
return error.cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Horrible hack to "recreate" the error without calling a constructor (since we want to re-use the stack).
|
const ex = new Error();
|
||||||
return Object.assign(Object.create(Error), {
|
ex.name = error.name;
|
||||||
name: error.name,
|
ex.stack = error.stack;
|
||||||
stack: error.stack,
|
ex.message = error.message;
|
||||||
message: error.message,
|
ex.cause = error.cause;
|
||||||
cause: error.cause,
|
return ex;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,13 +137,6 @@ function unpackAxiosError(error: unknown): unknown {
|
||||||
return error.cause;
|
return error.cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('code' in error) {
|
|
||||||
return {
|
|
||||||
code: error.code,
|
|
||||||
message: String(error),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// No data - this is a fallback to avoid leaking request/response details in the error
|
// No data - this is a fallback to avoid leaking request/response details in the error
|
||||||
return String(error);
|
return String(error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue