* Fix TS errors and warnings * Fix ESLint errors and warnings * Fix property typos in various places * Fix property data conversion * Add missing entity properties * Normalize logging and reduce spam * Check for missing request parameters * Allow mastodon API to work with local debugging * Safer error handling * Fix quote-post detection
This commit is contained in:
parent
2c2fb8a692
commit
16f483d273
13 changed files with 1275 additions and 1147 deletions
39
packages/backend/src/server/api/mastodon/MastodonLogger.ts
Normal file
39
packages/backend/src/server/api/mastodon/MastodonLogger.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import Logger, { Data } from '@/logger.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
|
||||
@Injectable()
|
||||
export class MastodonLogger {
|
||||
public readonly logger: Logger;
|
||||
|
||||
constructor(loggerService: LoggerService) {
|
||||
this.logger = loggerService.getLogger('masto-api');
|
||||
}
|
||||
|
||||
public error(endpoint: string, error: Data): void {
|
||||
this.logger.error(`Error in mastodon API endpoint ${endpoint}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
export function getErrorData(error: unknown): Data {
|
||||
if (error == null) return {};
|
||||
if (typeof(error) === 'string') return error;
|
||||
if (typeof(error) === 'object') {
|
||||
if ('response' in error) {
|
||||
if (typeof(error.response) === 'object' && error.response) {
|
||||
if ('data' in error.response) {
|
||||
if (typeof(error.response.data) === 'object' && error.response.data) {
|
||||
return error.response.data as Record<string, unknown>;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return error as Record<string, unknown>;
|
||||
}
|
||||
return { error };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue