refactor (backend): make error logs more verbose

This commit is contained in:
naskya 2024-02-21 22:23:24 +09:00
parent 72be21467b
commit c79248d07c
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
56 changed files with 234 additions and 218 deletions

View file

@ -4,6 +4,7 @@ import Xev from "xev";
import Logger from "@/services/logger.js";
import { envOption } from "../env.js";
import { inspect } from "node:util";
// for typeorm
import "reflect-metadata";
@ -82,7 +83,7 @@ if (!envOption.quiet) {
// Display detail of uncaught exception
process.on("uncaughtException", (err) => {
try {
logger.error(err);
logger.error(inspect(err));
} catch {}
});

View file

@ -13,6 +13,7 @@ import type { Config } from "@/config/types.js";
import { envOption } from "@/env.js";
import { showMachineInfo } from "@/misc/show-machine-info.js";
import { db, initDb } from "@/db/postgre.js";
import { inspect } from "node:util";
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);
@ -100,7 +101,7 @@ export async function masterMain() {
await connectDb();
} catch (e) {
bootLogger.error(
`Fatal error occurred during initialization: ${e}`,
`Fatal error occurred during initialization:\n${inspect(e)}`,
null,
true,
);
@ -182,15 +183,15 @@ async function connectDb(): Promise<void> {
// Try to connect to DB
try {
dbLogger.info("Connecting...");
dbLogger.info("Connecting to the database...");
await initDb();
const v = await db
.query("SHOW server_version")
.then((x) => x[0].server_version);
dbLogger.succ(`Connected: v${v}`);
} catch (e) {
dbLogger.error("Cannot connect", null, true);
dbLogger.error(e);
dbLogger.error("Failed to connect to the database", null, true);
dbLogger.error(inspect(e));
process.exit(1);
}
}

View file

@ -4,10 +4,11 @@
import { EventEmitter } from "node:events";
import boot from "./boot/index.js";
import { inspect } from "node:util";
Error.stackTraceLimit = Infinity;
EventEmitter.defaultMaxListeners = 128;
boot().catch((err) => {
console.error(err);
console.error(inspect(err));
});

View file

@ -1,6 +1,7 @@
// https://gist.github.com/nfantone/1eaa803772025df69d07f4dbf5df7e58
"use strict";
const inspect = require("node:util");
/**
* @callback BeforeShutdownListener
@ -71,9 +72,7 @@ async function shutdownHandler(signalOrEvent: string) {
} catch (err) {
if (err instanceof Error) {
console.warn(
`A shutdown handler failed before completing with: ${
err.message || err
}`,
`A shutdown handler failed before completing with:\n${inspect(err)}`,
);
}
}

View file

@ -2,6 +2,7 @@ import fetch from "node-fetch";
import { URLSearchParams } from "node:url";
import { getAgentByUrl } from "@/misc/fetch.js";
import config from "@/config/index.js";
import { inspect } from "node:util";
export async function verifyRecaptcha(secret: string, response: string) {
const result = await getCaptchaResponse(
@ -9,7 +10,7 @@ export async function verifyRecaptcha(secret: string, response: string) {
secret,
response,
).catch((e) => {
throw new Error(`recaptcha-request-failed: ${e.message}`);
throw new Error(`recaptcha-request-failed:\n${inspect(e)}`);
});
if (result.success !== true) {
@ -26,7 +27,7 @@ export async function verifyHcaptcha(secret: string, response: string) {
secret,
response,
).catch((e) => {
throw new Error(`hcaptcha-request-failed: ${e.message}`);
throw new Error(`hcaptcha-request-failed:\n${inspect(e)}`);
});
if (result.success !== true) {
@ -62,7 +63,7 @@ async function getCaptchaResponse(
//timeout: 10 * 1000,
agent: getAgentByUrl,
}).catch((e) => {
throw new Error(`${e.message || e}`);
throw new Error(`${inspect(e)}`);
});
if (!res.ok) {

View file

@ -5,6 +5,7 @@ import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
import Logger from "@/services/logger.js";
import { Cache } from "./cache.js";
import { redisClient } from "@/db/redis.js";
import { inspect } from "node:util";
export type Size = {
width: number;
@ -44,7 +45,7 @@ export async function getEmojiSize(url: string): Promise<Size> {
}
return { width, height };
} catch (e) {
throw new Error(`Unable to retrieve metadata: ${e}`);
throw new Error(`Unable to retrieve metadata:\n${inspect(e)}`);
}
}

View file

@ -7,6 +7,7 @@ import probeImageSize from "probe-image-size";
import isSvg from "is-svg";
import sharp from "sharp";
import { encode } from "blurhash";
import { inspect } from "node:util";
const pipeline = util.promisify(stream.pipeline);
@ -65,7 +66,7 @@ export async function getFileInfo(path: string): Promise<FileInfo> {
].includes(type.mime)
) {
const imageSize = await detectImageSize(path).catch((e) => {
warnings.push(`detectImageSize failed: ${e}`);
warnings.push(`detectImageSize failed:\n${inspect(e)}`);
return undefined;
});
@ -102,7 +103,7 @@ export async function getFileInfo(path: string): Promise<FileInfo> {
].includes(type.mime)
) {
blurhash = await getBlurhash(path).catch((e) => {
warnings.push(`getBlurhash failed: ${e}`);
warnings.push(`getBlurhash failed:\n${inspect(e)}`);
return undefined;
});
}

View file

@ -21,7 +21,7 @@ export class I18n<T extends Record<string, any>> {
}
}
return str;
} catch (e) {
} catch {
console.warn(`missing localization '${key}'`);
return key;
}

View file

@ -8,6 +8,7 @@ import * as tar from "tar-stream";
import gunzip from "gunzip-maybe";
import decompress from "decompress";
import * as Path from "node:path";
import { inspect } from "node:util";
const logger = new Logger("process-masto-notes");
@ -103,7 +104,7 @@ function unzipZip(fn: string, dir: string) {
function unzipTarGz(fn: string, dir: string) {
return new Promise(async (resolve, reject) => {
const onErr = (err: any) => {
logger.error(`pipe broken: ${err}`);
logger.error(`pipe broken:\n${inspect(err)}`);
reject();
};
try {
@ -120,7 +121,7 @@ function unzipTarGz(fn: string, dir: string) {
.on("error", onErr);
next();
} catch (e) {
logger.error(`create dir error:${e}`);
logger.error(`create dir error:\n${inspect(e)}`);
reject();
}
});
@ -136,7 +137,7 @@ function unzipTarGz(fn: string, dir: string) {
.pipe(extract)
.on("error", onErr);
} catch (e) {
logger.error(`unzipTarGz error: ${e}`);
logger.error(`unzipTarGz error:\n${inspect(e)}`);
reject();
}
});

View file

@ -7,6 +7,7 @@ import { MoreThan } from "typeorm";
import { index } from "@/services/note/create.js";
import { Note } from "@/models/entities/note.js";
import meilisearch from "@/db/meilisearch.js";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("index-all-notes");
@ -43,7 +44,7 @@ export default async function indexAllNotes(
relations: ["user"],
});
} catch (e: any) {
logger.error(`Failed to query notes ${e}`);
logger.error(`Failed to query notes:\n${inspect(e)}`);
done(e);
break;
}

View file

@ -11,6 +11,7 @@ import { createTemp, createTempDir } from "@/misc/create-temp.js";
import { downloadUrl } from "@/misc/download-url.js";
import config from "@/config/index.js";
import { IsNull } from "typeorm";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("export-custom-emojis");
@ -76,7 +77,7 @@ export async function exportCustomEmojis(
downloaded = true;
} catch (e) {
// TODO: 何度か再試行
logger.error(e instanceof Error ? e : new Error(e as string));
logger.error(inspect(e));
}
if (!downloaded) {

View file

@ -9,6 +9,7 @@ import { Users, DriveFiles } from "@/models/index.js";
import type { DbUserImportJobData } from "@/queue/types.js";
import block from "@/services/blocking/create.js";
import { IsNull } from "typeorm";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("import-blocking");
@ -70,7 +71,7 @@ export async function importBlocking(
await block(user, target);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
logger.warn(`Error in line ${linenum}:\n${inspect(e)}`);
}
}

View file

@ -9,6 +9,7 @@ import { Users, DriveFiles } from "@/models/index.js";
import type { DbUserImportJobData } from "@/queue/types.js";
import { queueLogger } from "../../logger.js";
import type Bull from "bull";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("import-following");
@ -68,7 +69,7 @@ export async function importFollowing(
follow(user, target);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
logger.warn(`Error in line ${linenum}:\n${inspect(e)}`);
}
}
} else {
@ -106,7 +107,7 @@ export async function importFollowing(
follow(user, target);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
logger.warn(`Error in line ${linenum}:\n${inspect(e)}`);
}
}
}

View file

@ -10,6 +10,7 @@ import type { DbUserImportJobData } from "@/queue/types.js";
import type { User } from "@/models/entities/user.js";
import { genId } from "@/misc/gen-id.js";
import { IsNull } from "typeorm";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("import-muting");
@ -71,7 +72,7 @@ export async function importMuting(
await mute(user, target);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
logger.warn(`Error in line ${linenum}: ${inspect(e)}`);
}
}

View file

@ -8,6 +8,7 @@ import {
createImportCkPostJob,
createImportMastoPostJob,
} from "@/queue/index.js";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("import-posts");
@ -44,7 +45,7 @@ export async function importPosts(
}
} catch (e) {
// handle error
logger.warn(`Failed reading Mastodon archive: ${e}`);
logger.warn(`Failed to read Mastodon archive:\n${inspect(e)}`);
}
logger.succ("Mastodon archive imported");
done();
@ -69,7 +70,7 @@ export async function importPosts(
}
} catch (e) {
// handle error
logger.warn(`Error reading: ${e}`);
logger.warn(`Error occured while reading:\n${inspect(e)}`);
}
logger.succ("Imported");

View file

@ -15,6 +15,7 @@ import {
import { genId } from "@/misc/gen-id.js";
import type { DbUserImportJobData } from "@/queue/types.js";
import { IsNull } from "typeorm";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("import-user-lists");
@ -87,7 +88,7 @@ export async function importUserLists(
pushUserToUserList(target, list!);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
logger.warn(`Error in line ${linenum}:\n${inspect(e)}`);
}
}

View file

@ -23,6 +23,7 @@ import type { CacheableRemoteUser } from "@/models/entities/user.js";
import type { UserPublickey } from "@/models/entities/user-publickey.js";
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
import { verifySignature } from "@/remote/activitypub/check-fetch.js";
import { inspect } from "node:util";
const logger = new Logger("inbox");
@ -78,9 +79,7 @@ export default async (job: Bull.Job<InboxJobData>): Promise<string> => {
if (e.isClientError) {
return `skip: Ignored deleted actors on both ends ${activity.actor} - ${e.statusCode}`;
}
throw new Error(
`Error in actor ${activity.actor} - ${e.statusCode || e}`,
);
throw new Error(`Error in actor ${activity.actor}\n${inspect(e)}`);
}
}
}

View file

@ -4,6 +4,7 @@ import { Emojis } from "@/models/index.js";
import { queueLogger } from "../../logger.js";
import { getEmojiSize } from "@/misc/emoji-meta.js";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("local-emoji-size");
@ -27,7 +28,7 @@ export async function setLocalEmojiSizes(
});
} catch (e) {
logger.error(
`Unable to set emoji size (${i + 1}/${emojis.length}): ${e}`,
`Unable to set emoji size (${i + 1}/${emojis.length}):\n${inspect(e)}`,
);
/* skip if any error happens */
} finally {

View file

@ -4,6 +4,7 @@ import { UserProfiles } from "@/models/index.js";
import { Not } from "typeorm";
import { queueLogger } from "../../logger.js";
import { verifyLink } from "@/services/fetch-rel-me.js";
import { inspect } from "node:util";
const logger = queueLogger.createSubLogger("verify-links");
@ -32,7 +33,7 @@ export async function verifyLinks(
fields: user.fields,
});
} catch (e) {
logger.error(`Failed to update user ${user.userId} ${e}`);
logger.error(`Failed to update user ${user.userId}:\n${inspect(e)}`);
done(e);
}
}

View file

@ -3,6 +3,8 @@ import { Users, Followings } from "@/models/index.js";
import type { ILocalUser, IRemoteUser, User } from "@/models/entities/user.js";
import { deliver } from "@/queue/index.js";
import { skippedInstances } from "@/misc/skipped-instances.js";
import { apLogger } from "./logger";
import { inspect } from "node:util";
//#region types
interface IRecipe {
@ -131,8 +133,7 @@ export default class DeliverManager {
host: new URL(inbox).host,
});
} catch (error) {
console.error(error);
console.error(`Invalid Inbox ${inbox}`);
apLogger.error(`Invalid Inbox ${inbox}:\n${inspect(error)}`);
}
}

View file

@ -4,6 +4,7 @@ import acceptFollow from "./follow.js";
import type { IAccept } from "../../type.js";
import { isFollow, getApType } from "../../type.js";
import { apLogger } from "../../logger.js";
import { inspect } from "node:util";
const logger = apLogger;
@ -18,7 +19,7 @@ export default async (
const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch((e) => {
logger.error(`Resolution failed: ${e}`);
logger.error(`Resolution failed:\n${inspect(e)}`);
throw e;
});

View file

@ -11,6 +11,7 @@ import { parseAudience } from "../../audience.js";
import { StatusError } from "@/misc/fetch.js";
import { Notes } from "@/models/index.js";
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
import { inspect } from "node:util";
const logger = apLogger;
@ -53,9 +54,7 @@ export default async function (
return;
}
logger.warn(
`Error in announce target ${targetUri} - ${e.statusCode || e}`,
);
logger.warn(`Error in announce target ${targetUri}:\n${inspect(e)}`);
}
throw e;
}

View file

@ -5,6 +5,7 @@ import type { ICreate } from "../../type.js";
import { getApId, isPost, getApType } from "../../type.js";
import { apLogger } from "../../logger.js";
import { toArray, concat, unique } from "@/prelude/array.js";
import { inspect } from "node:util";
const logger = apLogger;
@ -39,7 +40,7 @@ export default async (
const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch((e) => {
logger.error(`Resolution failed: ${e}`);
logger.error(`Resolution failed:\n${inspect(e)}`);
throw e;
});

View file

@ -40,6 +40,7 @@ import move from "./move/index.js";
import type { IObject, IActivity } from "../type.js";
import { extractDbHost } from "@/misc/convert-host.js";
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
import { inspect } from "node:util";
export async function performActivity(
actor: CacheableRemoteUser,
@ -54,9 +55,7 @@ export async function performActivity(
try {
await performOneActivity(actor, act);
} catch (err) {
if (err instanceof Error || typeof err === "string") {
apLogger.error(err);
}
apLogger.error(inspect(err));
}
}
} else {
@ -90,9 +89,9 @@ async function performOneActivity(
} else if (isReject(activity)) {
await reject(actor, activity);
} else if (isAdd(activity)) {
await add(actor, activity).catch((err) => apLogger.error(err));
await add(actor, activity).catch((err) => apLogger.error(inspect(err)));
} else if (isRemove(activity)) {
await remove(actor, activity).catch((err) => apLogger.error(err));
await remove(actor, activity).catch((err) => apLogger.error(inspect(err)));
} else if (isAnnounce(activity)) {
await announce(actor, activity);
} else if (isLike(activity)) {

View file

@ -4,6 +4,7 @@ import rejectFollow from "./follow.js";
import type { IReject } from "../../type.js";
import { isFollow, getApType } from "../../type.js";
import { apLogger } from "../../logger.js";
import { inspect } from "node:util";
const logger = apLogger;
@ -18,7 +19,7 @@ export default async (
const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch((e) => {
logger.error(`Resolution failed: ${e}`);
logger.error(`Resolution failed:\n${inspect(e)}`);
throw e;
});

View file

@ -15,6 +15,7 @@ import undoAccept from "./accept.js";
import { undoAnnounce } from "./announce.js";
import Resolver from "../../resolver.js";
import { apLogger } from "../../logger.js";
import { inspect } from "node:util";
const logger = apLogger;
@ -33,7 +34,7 @@ export default async (
const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch((e) => {
logger.error(`Resolution failed: ${e}`);
logger.error(`Resolution failed:\n${inspect(e)}`);
throw e;
});

View file

@ -5,6 +5,7 @@ import { apLogger } from "../../logger.js";
import { updateNote } from "../../models/note.js";
import Resolver from "../../resolver.js";
import { updatePerson } from "../../models/person.js";
import { inspect } from "node:util";
/**
* Handler for the Update activity
@ -22,7 +23,7 @@ export default async (
const resolver = new Resolver();
const object = await resolver.resolve(activity.object).catch((e) => {
apLogger.error(`Resolution failed: ${e}`);
apLogger.error(`Resolution failed:\n${inspect(e)}`);
throw e;
});

View file

@ -50,6 +50,7 @@ import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js";
import { truncate } from "@/misc/truncate.js";
import { type Size, getEmojiSize } from "@/misc/emoji-meta.js";
import { langmap } from "@/misc/langmap.js";
import { inspect } from "node:util";
const logger = apLogger;
@ -242,9 +243,7 @@ export async function createNote(
}
}
logger.warn(
`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`,
);
logger.warn(`Error in inReplyTo ${note.inReplyTo}:\n${inspect(e)}`);
throw e;
})
: null;
@ -359,7 +358,7 @@ export async function createNote(
}
const emojis = await extractEmojis(note.tag || [], actor.host).catch((e) => {
logger.info(`extractEmojis: ${e}`);
logger.info(`extractEmojis:\n${inspect(e)}`);
return [] as Emoji[];
});

View file

@ -47,6 +47,7 @@ import Resolver from "../resolver.js";
import { extractApHashtags } from "./tag.js";
import { resolveNote, extractEmojis } from "./note.js";
import { resolveImage } from "./image.js";
import { inspect } from "node:util";
const logger = apLogger;
@ -349,7 +350,7 @@ export async function createPerson(
throw new Error("already registered");
}
} else {
logger.error(e instanceof Error ? e : new Error(e as string));
logger.error(inspect(e));
throw e;
}
}
@ -389,7 +390,7 @@ export async function createPerson(
//#region Get custom emoji
const emojis = await extractEmojis(person.tag || [], host).catch((e) => {
logger.info(`extractEmojis: ${e}`);
logger.info(`extractEmojis:\n${inspect(e)}`);
return [] as Emoji[];
});
@ -400,7 +401,9 @@ export async function createPerson(
});
//#endregion
await updateFeatured(user!.id, resolver).catch((err) => logger.error(err));
await updateFeatured(user!.id, resolver).catch((err) =>
logger.error(inspect(err)),
);
return user!;
}
@ -451,7 +454,7 @@ export async function updatePerson(
// Custom pictogram acquisition
const emojis = await extractEmojis(person.tag || [], user.host).catch((e) => {
logger.info(`extractEmojis: ${e}`);
logger.info(`extractEmojis:\n${inspect(e)}`);
return [] as Emoji[];
});
@ -617,7 +620,9 @@ export async function updatePerson(
},
);
await updateFeatured(user.id, resolver).catch((err) => logger.error(err));
await updateFeatured(user.id, resolver).catch((err) =>
logger.error(inspect(err)),
);
}
/**

View file

@ -8,6 +8,7 @@ import { toPuny } from "@/misc/convert-host.js";
import webFinger from "./webfinger.js";
import { createPerson, updatePerson } from "./activitypub/models/person.js";
import { remoteLogger } from "./logger.js";
import { inspect } from "node:util";
const logger = remoteLogger.createSubLogger("resolve-user");
@ -118,9 +119,7 @@ async function resolveSelf(acctLower: string) {
logger.info(`WebFinger for ${chalk.yellow(acctLower)}`);
const finger = await webFinger(acctLower).catch((e) => {
logger.error(
`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${
e.statusCode || e.message
}`,
`Failed to WebFinger for ${chalk.yellow(acctLower)}:\n${inspect(e)}`,
);
throw new Error(
`Failed to WebFinger for ${acctLower}: ${e.statusCode || e.message}`,

View file

@ -58,7 +58,7 @@ function inbox(ctx: Router.RouterContext) {
headers: ["(request-target)", "digest", "host", "date"],
});
} catch (e) {
serverLogger.warn(`inbox: signature parse error: ${inspect(e)}`);
serverLogger.warn(`inbox: signature parse error:\n${inspect(e)}`);
ctx.status = 401;
if (e instanceof Error) {

View file

@ -7,6 +7,7 @@ import { MINUTE } from "@/const.js";
import define from "@/server/api/define.js";
import { apiLogger } from "@/server/api/logger.js";
import { ApiError } from "@/server/api/error.js";
import { inspect } from "node:util";
export const meta = {
tags: ["drive"],
@ -112,9 +113,8 @@ export default define(
});
return await DriveFiles.pack(driveFile, { self: true });
} catch (e) {
if (e instanceof Error || typeof e === "string") {
apiLogger.error(e);
}
if (typeof e === "string") apiLogger.error(e);
if (e instanceof Error) apiLogger.error(inspect(e));
if (e instanceof IdentifiableError) {
if (e.id === "282f77bf-5816-4f72-9264-aa14d8261a21")
throw new ApiError(meta.errors.inappropriate);

View file

@ -9,6 +9,7 @@ import { apiLogger } from "@/server/api/logger.js";
import define from "@/server/api/define.js";
import { ApiError } from "@/server/api/error.js";
import { parse } from "@/misc/acct.js";
import { inspect } from "node:util";
export const meta = {
tags: ["users"],
@ -74,7 +75,7 @@ export default define(meta, paramDef, async (ps, user) => {
const { username, host } = parse(line);
const aka = await resolveUser(username, host).catch((e) => {
apiLogger.warn(`failed to resolve remote user: ${e}`);
apiLogger.warn(`failed to resolve remote user:\n${inspect(e)}`);
throw new ApiError(meta.errors.noSuchUser);
});

View file

@ -13,6 +13,7 @@ import { Followings, Users } from "@/models/index.js";
import config from "@/config/index.js";
import { publishMainStream } from "@/services/stream.js";
import { parse } from "@/misc/acct.js";
import { inspect } from "node:util";
export const meta = {
tags: ["users"],
@ -99,7 +100,7 @@ export default define(meta, paramDef, async (ps, user) => {
if (!host) throw new ApiError(meta.errors.notRemote);
const moveTo: User = await resolveUser(username, host).catch((e) => {
apiLogger.warn(`failed to resolve remote user: ${e}`);
apiLogger.warn(`failed to resolve remote user:\n${inspect(e)}`);
throw new ApiError(meta.errors.noSuchMoveTarget);
});
let fromUrl: string | null = user.uri;

View file

@ -22,8 +22,10 @@ import signupPending from "./private/signup-pending.js";
import verifyEmail from "./private/verify-email.js";
import { koaBody } from "koa-body";
import { convertAttachment } from "./mastodon/converters.js";
import { apiLogger } from "./logger.js";
import { convertId, IdConvertType as IdType } from "backend-rs";
import { inspect } from "node:util";
// re-export native rust id conversion (function and enum)
export { IdType, convertId };
@ -90,7 +92,7 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => {
const data = await client.uploadMedia(multipartData);
ctx.body = convertAttachment(data.data as Entity.Attachment);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -109,7 +111,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => {
const data = await client.uploadMedia(multipartData, ctx.request.body);
ctx.body = convertAttachment(data.data as Entity.Attachment);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -16,6 +16,8 @@ import {
import { convertId, IdType } from "@/server/api/index.js";
import { Users } from "@/models/index.js";
import { IsNull } from "typeorm";
import { apiLogger } from "../logger.js";
import { inspect } from "node:util";
export function getClient(
BASE_URL: string,
@ -45,7 +47,7 @@ export function apiMastodonCompatible(router: Router): void {
const data = await client.getInstanceCustomEmojis();
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -73,7 +75,7 @@ export function apiMastodonCompatible(router: Router): void {
: convertAccount((await client.getAccount(admin.id)).data);
ctx.body = await getInstance(data.data, contact);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -89,7 +91,7 @@ export function apiMastodonCompatible(router: Router): void {
convertAnnouncement(announcement),
);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -107,7 +109,7 @@ export function apiMastodonCompatible(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -123,7 +125,7 @@ export function apiMastodonCompatible(router: Router): void {
const data = await client.getFilters();
ctx.body = data.data.map((filter) => convertFilter(filter));
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -138,7 +140,7 @@ export function apiMastodonCompatible(router: Router): void {
const data = await client.getInstanceTrends();
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -153,7 +155,7 @@ export function apiMastodonCompatible(router: Router): void {
const data = await client.getPreferences();
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -9,6 +9,8 @@ import {
convertRelationship,
convertStatus,
} from "../converters.js";
import { apiLogger } from "../../logger.js";
import { inspect } from "node:util";
const relationshipModel = {
id: "",
@ -52,8 +54,7 @@ export function apiAccountMastodon(router: Router): void {
console.log(acct);
ctx.body = acct;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -68,8 +69,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertAccount(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -85,8 +85,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertAccount(data.data.accounts[0]);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -119,10 +118,9 @@ export function apiAccountMastodon(router: Router): void {
convertRelationship(relationship),
);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
let data = e.response.data;
data.users = users;
console.error(data);
ctx.status = 401;
ctx.body = data;
}
@ -136,8 +134,7 @@ export function apiAccountMastodon(router: Router): void {
const data = await client.getAccount(calcId);
ctx.body = convertAccount(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -155,8 +152,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -174,8 +170,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((tag) => convertFeaturedTag(tag));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -194,8 +189,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -214,8 +208,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -233,8 +226,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((list) => convertList(list));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -254,8 +246,7 @@ export function apiAccountMastodon(router: Router): void {
acct.following = true;
ctx.body = acct;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -275,8 +266,7 @@ export function apiAccountMastodon(router: Router): void {
acct.following = false;
ctx.body = acct;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -294,8 +284,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertRelationship(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -313,8 +302,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertRelationship(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -333,8 +321,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertRelationship(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -352,8 +339,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertRelationship(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -367,8 +353,7 @@ export function apiAccountMastodon(router: Router): void {
const data = await client.getFeaturedTags();
ctx.body = data.data.map((tag) => convertFeaturedTag(tag));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -381,8 +366,7 @@ export function apiAccountMastodon(router: Router): void {
const data = await client.getFollowedTags();
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -397,8 +381,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -413,8 +396,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -429,8 +411,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -445,8 +426,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -461,8 +441,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -479,8 +458,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertRelationship(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -498,8 +476,7 @@ export function apiAccountMastodon(router: Router): void {
);
ctx.body = convertRelationship(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -1,5 +1,7 @@
import Router from "@koa/router";
import { getClient } from "../ApiMastodonCompatibleService.js";
import { apiLogger } from "@/server/api/logger.js";
import { inspect } from "node:util";
const readScope = [
"read:account",
@ -70,7 +72,7 @@ export function apiAuthMastodon(router: Router): void {
console.log(returns);
ctx.body = returns;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -2,6 +2,8 @@ import Router from "@koa/router";
import { getClient } from "../ApiMastodonCompatibleService.js";
import { IdType, convertId } from "@/server/api/index.js";
import { convertFilter } from "../converters.js";
import { apiLogger } from "@/server/api/logger.js";
import { inspect } from "node:util";
export function apiFilterMastodon(router: Router): void {
router.get("/v1/filters", async (ctx) => {
@ -13,7 +15,7 @@ export function apiFilterMastodon(router: Router): void {
const data = await client.getFilters();
ctx.body = data.data.map((filter) => convertFilter(filter));
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -30,7 +32,7 @@ export function apiFilterMastodon(router: Router): void {
);
ctx.body = convertFilter(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -45,7 +47,7 @@ export function apiFilterMastodon(router: Router): void {
const data = await client.createFilter(body.phrase, body.context, body);
ctx.body = convertFilter(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -64,7 +66,7 @@ export function apiFilterMastodon(router: Router): void {
);
ctx.body = convertFilter(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -81,7 +83,7 @@ export function apiFilterMastodon(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -3,6 +3,9 @@ import { convertId, IdType } from "@/server/api/index.js";
import { getClient } from "../ApiMastodonCompatibleService.js";
import { convertTimelinesArgsId } from "./timeline.js";
import { convertNotification } from "../converters.js";
import { apiLogger } from "@/server/api/logger.js";
import { inspect } from "node:util";
function toLimitToInt(q: any) {
if (q.limit) if (typeof q.limit === "string") q.limit = parseInt(q.limit, 10);
return q;
@ -30,7 +33,7 @@ export function apiNotificationsMastodon(router: Router): void {
});
ctx.body = ret;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -55,7 +58,7 @@ export function apiNotificationsMastodon(router: Router): void {
data.type = "favourite";
}
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -70,7 +73,7 @@ export function apiNotificationsMastodon(router: Router): void {
const data = await client.dismissNotifications();
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -87,7 +90,7 @@ export function apiNotificationsMastodon(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -4,6 +4,8 @@ import axios from "axios";
import { Converter } from "megalodon";
import { convertTimelinesArgsId, limitToInt } from "./timeline.js";
import { convertAccount, convertStatus } from "../converters.js";
import { apiLogger } from "@/server/api/logger.js";
import { inspect } from "node:util";
export function apiSearchMastodon(router: Router): void {
router.get("/v1/search", async (ctx) => {
@ -17,7 +19,7 @@ export function apiSearchMastodon(router: Router): void {
const data = await client.search(query.q, type, query);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -50,7 +52,7 @@ export function apiSearchMastodon(router: Router): void {
hashtags: tags?.data?.hashtags ?? [],
};
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -66,7 +68,7 @@ export function apiSearchMastodon(router: Router): void {
);
ctx.body = data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -89,7 +91,7 @@ export function apiSearchMastodon(router: Router): void {
console.log(data);
ctx.body = data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -109,8 +111,7 @@ async function getHighlight(
const data: MisskeyEntity.Note[] = api.data;
return data.map((note) => new Converter(BASE_URL).note(note, domain));
} catch (e: any) {
console.log(e);
console.log(e.response.data);
apiLogger.info(inspect(e));
return [];
}
}
@ -131,7 +132,7 @@ async function getFeaturedUser(
state: "alive",
});
const data: MisskeyEntity.UserDetail[] = api.data;
console.log(data);
apiLogger.info(inspect(data));
return data.map((u) => {
return {
source: "past_interactions",
@ -139,8 +140,7 @@ async function getFeaturedUser(
};
});
} catch (e: any) {
console.log(e);
console.log(e.response.data);
apiLogger.info(inspect(e));
return [];
}
}

View file

@ -12,6 +12,8 @@ import {
convertStatus,
} from "../converters.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
import { apiLogger } from "@/server/api/logger.js";
import { inspect } from "node:util";
function normalizeQuery(data: any) {
const str = querystring.stringify(data);
@ -54,7 +56,7 @@ export function apiStatusMastodon(router: Router): void {
const data = await client.deleteEmojiReaction(id, react);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -91,7 +93,7 @@ export function apiStatusMastodon(router: Router): void {
const data = await client.postStatus(text, body);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -106,7 +108,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = ctx.status == 404 ? 404 : 401;
ctx.body = e.response.data;
}
@ -121,7 +123,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e.response.data, request.params.id);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -153,7 +155,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -171,7 +173,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -189,7 +191,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -207,7 +209,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -229,8 +231,7 @@ export function apiStatusMastodon(router: Router): void {
//const data = await client.favouriteStatus(ctx.params.id) as any;
ctx.body = convertStatus(a.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -251,7 +252,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -270,7 +271,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -289,7 +290,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -308,7 +309,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -327,7 +328,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -346,7 +347,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -365,7 +366,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -385,7 +386,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -405,7 +406,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertStatus(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -422,7 +423,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertAttachment(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -438,7 +439,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertAttachment(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -453,7 +454,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertPoll(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -471,7 +472,7 @@ export function apiStatusMastodon(router: Router): void {
);
ctx.body = convertPoll(data.data);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -8,6 +8,8 @@ import {
convertStatus,
} from "../converters.js";
import { convertId, IdType } from "@/server/api/index.js";
import { apiLogger } from "@/server/api/logger.js";
import { inspect } from "node:util";
export function limitToInt(q: ParsedUrlQuery) {
let object: any = q;
@ -71,8 +73,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -90,8 +91,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -107,8 +107,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -126,8 +125,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data.map((status) => convertStatus(status));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -145,8 +143,7 @@ export function apiTimelineMastodon(router: Router): void {
convertConversation(conversation),
);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -159,8 +156,7 @@ export function apiTimelineMastodon(router: Router): void {
const data = await client.getLists();
ctx.body = data.data.map((list) => convertList(list));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -177,8 +173,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = convertList(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -192,8 +187,7 @@ export function apiTimelineMastodon(router: Router): void {
const data = await client.createList((ctx.request.body as any).title);
ctx.body = convertList(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -211,8 +205,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = convertList(data.data);
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -230,8 +223,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -250,8 +242,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -272,8 +263,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}
@ -294,8 +284,7 @@ export function apiTimelineMastodon(router: Router): void {
);
ctx.body = data.data;
} catch (e: any) {
console.error(e);
console.error(e.response.data);
apiLogger.error(inspect(e));
ctx.status = 401;
ctx.body = e.response.data;
}

View file

@ -9,6 +9,7 @@ import { sendEmail } from "@/services/send-email.js";
import { genId } from "@/misc/gen-id.js";
import { validateEmailForAccount } from "@/services/validate-email-for-account.js";
import { hashPassword } from "@/misc/password.js";
import { inspect } from "node:util";
export default async (ctx: Koa.Context) => {
const body = ctx.request.body;

View file

@ -27,6 +27,8 @@ import type Channel from "./channel.js";
import type { StreamEventEmitter, StreamMessages } from "./types.js";
import { Converter } from "megalodon";
import { getClient } from "@/server/api/mastodon/ApiMastodonCompatibleService.js";
import { apiLogger } from "@/server/api/logger.js";
import { inspect } from "node:util";
/**
* Main stream connection
@ -183,7 +185,7 @@ export default class Connection {
const tl = await client.getHomeTimeline();
for (const t of tl.data) forSubscribe.push(t.id);
} catch (e: any) {
console.error(e);
apiLogger.error(inspect(e));
}
} else if (simpleObj.stream === "public:local") {
this.currentSubscribe.push(["public:local"]);

View file

@ -16,6 +16,7 @@ import { GenerateVideoThumbnail } from "@/services/drive/generate-video-thumbnai
import { StatusError } from "@/misc/fetch.js";
import { ByteRangeReadable } from "./byte-range-readable.js";
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
import { inspect } from "node:util";
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);
@ -106,7 +107,7 @@ export default async function (ctx: Koa.Context) {
);
ctx.set("Cache-Control", "max-age=31536000, immutable");
} catch (e) {
serverLogger.error(`${e}`);
serverLogger.error(`${inspect(e)}`);
if (e instanceof StatusError && e.isClientError) {
ctx.status = e.statusCode;

View file

@ -33,6 +33,7 @@ import { initializeStreamingServer } from "./api/streaming.js";
import { koaBody } from "koa-body";
import removeTrailingSlash from "koa-remove-trailing-slashes";
import { v4 as uuid } from "uuid";
import { inspect } from "node:util";
export const serverLogger = new Logger("server", "gray", false);
@ -194,10 +195,10 @@ mastoRouter.post("/oauth/token", async (ctx) => {
scope: body.scope || "read write follow push",
created_at: Math.floor(new Date().getTime() / 1000),
};
console.log("token-response", ret);
serverLogger.info("token-response", ret);
ctx.body = ret;
} catch (err: any) {
console.error(err);
serverLogger.error(inspect(err));
ctx.status = 401;
ctx.body = err.response.data;
}

View file

@ -12,6 +12,7 @@ import { StatusError } from "@/misc/fetch.js";
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
import { serverLogger } from "../index.js";
import { isMimeImage } from "@/misc/is-mime-image.js";
import { inspect } from "node:util";
export async function proxyMedia(ctx: Koa.Context) {
let url = "url" in ctx.query ? ctx.query.url : `https://${ctx.params.url}`;
@ -130,7 +131,7 @@ export async function proxyMedia(ctx: Koa.Context) {
ctx.set("Cache-Control", "max-age=31536000, immutable");
ctx.body = image.data;
} catch (e) {
serverLogger.error(`${e}`);
serverLogger.error(`${inspect(e)}`);
if (e instanceof StatusError && (e.statusCode === 302 || e.isClientError)) {
ctx.status = e.statusCode;

View file

@ -5,6 +5,7 @@ import Logger from "@/services/logger.js";
import config from "@/config/index.js";
import { query } from "@/prelude/url.js";
import { getJson } from "@/misc/fetch.js";
import { inspect } from "node:util";
const logger = new Logger("url-preview");
@ -69,7 +70,7 @@ export const urlPreviewHandler = async (ctx: Koa.Context) => {
ctx.body = summary;
} catch (err) {
logger.warn(`Failed to get preview of ${url}: ${err}`);
logger.warn(`Failed to get preview of ${url}:\n${inspect(err)}`);
ctx.status = 200;
ctx.set("Cache-Control", "max-age=86400, immutable");
ctx.body = "{}";

View file

@ -33,6 +33,7 @@ import { convertSharpToWebp } from "./image-processor.js";
import { driveLogger } from "./logger.js";
import { GenerateVideoThumbnail } from "./generate-video-thumbnail.js";
import { deleteFile } from "./delete-file.js";
import { inspect } from "node:util";
const logger = driveLogger.createSubLogger("register", "yellow");
@ -234,7 +235,7 @@ export async function generateAlts(
thumbnail,
};
} catch (err) {
logger.warn(`GenerateVideoThumbnail failed: ${err}`);
logger.warn(`GenerateVideoThumbnail failed:\n${inspect(err)}`);
return {
webpublic: null,
thumbnail: null,
@ -289,7 +290,7 @@ export async function generateAlts(
metadata.height <= 2048
);
} catch (err) {
logger.warn(`sharp failed: ${err}`);
logger.warn(`sharp failed:\n${inspect(err)}`);
return {
webpublic: null,
thumbnail: null,
@ -315,7 +316,7 @@ export async function generateAlts(
logger.debug("web image not created (not an required image)");
}
} catch (err) {
logger.warn("web image not created (an error occured)", err as Error);
logger.warn(`web image not created (an error occured):\n${inspect(err)}`);
}
} else {
if (satisfyWebpublic)
@ -342,7 +343,7 @@ export async function generateAlts(
logger.debug("thumbnail not created (not an required file)");
}
} catch (err) {
logger.warn("thumbnail not created (an error occured)", err as Error);
logger.warn(`thumbnail not created (an error occured):\n${inspect(err)}`);
}
// #endregion thumbnail
@ -629,7 +630,7 @@ export async function addFile({
userId: user ? user.id : IsNull(),
})) as DriveFile;
} else {
logger.error(err as Error);
logger.error(inspect(err));
throw err;
}
}

View file

@ -2,6 +2,7 @@ import { URL } from "node:url";
import S3 from "aws-sdk/clients/s3.js"; // TODO: migrate to SDK v3
import type { Meta } from "@/models/entities/meta.js";
import { getAgentByUrl } from "@/misc/fetch.js";
import { inspect } from "node:util";
export function getS3(meta: Meta) {
const u =
@ -27,7 +28,7 @@ export function getS3(meta: Meta) {
});
} catch (e) {
throw new Error(
`Failed to construct S3 client, assembled S3 URL: ${u}\n${e}`,
`Failed to construct S3 client, assembled S3 URL: ${u}\n${inspect(e)}`,
);
}
}

View file

@ -7,6 +7,7 @@ import type { DriveFile } from "@/models/entities/drive-file.js";
import { DriveFiles } from "@/models/index.js";
import { driveLogger } from "./logger.js";
import { addFile } from "./add-file.js";
import { inspect } from "node:util";
const logger = driveLogger.createSubLogger("downloader");
@ -78,10 +79,7 @@ export async function uploadFromUrl({
logger.succ(`Got: ${driveFile.id}`);
return driveFile!;
} catch (e) {
logger.error(`Failed to create drive file: ${e}`, {
url: url,
e: e,
});
logger.error(`Failed to create drive file:\n${inspect(e)}`);
throw e;
} finally {
cleanup();

View file

@ -7,6 +7,7 @@ import type { Instance } from "@/models/entities/instance.js";
import { Instances } from "@/models/index.js";
import { getFetchInstanceMetadataLock } from "@/misc/app-lock.js";
import Logger from "@/services/logger.js";
import { inspect } from "node:util";
const logger = new Logger("metadata", "cyan");
@ -77,7 +78,9 @@ export async function fetchInstanceMetadata(
logger.succ(`Successfuly updated metadata of ${instance.host}`);
} catch (e) {
logger.error(`Failed to update metadata of ${instance.host}: ${e}`);
logger.error(
`Failed to update metadata of ${instance.host}:\n${inspect(e)}`,
);
} finally {
await lock.release();
}
@ -111,7 +114,7 @@ async function fetchNodeinfo(instance: Instance): Promise<NodeInfo> {
if (e.statusCode === 404) {
throw new Error("No nodeinfo provided");
} else {
throw new Error(e.statusCode || e.message);
throw new Error(inspect(e));
}
})) as Record<string, unknown>;
@ -137,14 +140,16 @@ async function fetchNodeinfo(instance: Instance): Promise<NodeInfo> {
}
const info = await getJson(link.href).catch((e) => {
throw new Error(e.statusCode || e.message);
throw new Error(inspect(e));
});
logger.succ(`Successfuly fetched nodeinfo of ${instance.host}`);
return info as NodeInfo;
} catch (e) {
logger.error(`Failed to fetch nodeinfo of ${instance.host}: ${e.message}`);
logger.error(
`Failed to fetch nodeinfo of ${instance.host}:\n${inspect(e)}`,
);
throw e;
}

View file

@ -68,6 +68,10 @@ import meilisearch from "@/db/meilisearch.js";
import { redisClient } from "@/db/redis.js";
import { Mutex } from "redis-semaphore";
import { langmap } from "@/misc/langmap.js";
import Logger from "@/services/logger.js";
import { inspect } from "node:util";
const logger = new Logger("create-note");
const mutedWordsCache = new Cache<
{ userId: UserProfile["userId"]; mutedWords: UserProfile["mutedWords"] }[]
@ -814,7 +818,7 @@ async function insertNote(
throw err;
}
console.error(e);
logger.error(inspect(e));
throw e;
}

View file

@ -2,6 +2,7 @@ import * as nodemailer from "nodemailer";
import { fetchMeta } from "@/misc/fetch-meta.js";
import Logger from "@/services/logger.js";
import config from "@/config/index.js";
import { inspect } from "node:util";
export const logger = new Logger("email");
@ -67,7 +68,7 @@ export async function sendEmail(
logger.info(`Message sent: ${info.messageId}`);
} catch (err) {
logger.error(err as Error);
logger.error(inspect(err));
throw err;
}
}

View file

@ -95,9 +95,7 @@
<i :class="icon('ph-eye-slash')"></i>
</div>
<div :class="$style.body">
<span :class="$style.itemTitle">{{
i18n.ts.private
}}</span>
<span :class="$style.itemTitle">{{ i18n.ts.private }}</span>
<span :class="$style.itemDescription">{{
i18n.ts.privateDescription
}}</span>