Refactor debugging and logging more

This commit is contained in:
Jesse Wierzbinski 2024-04-14 01:20:55 -10:00
parent 82c6dc17a8
commit ab6fe6988c
No known key found for this signature in database
20 changed files with 230 additions and 123 deletions

View file

@ -35,6 +35,8 @@ import {
statusToMentions,
user,
} from "~drizzle/schema";
import { dualLogger } from "@loggers";
import { LogLevel } from "~packages/log-manager";
import type { Note } from "~types/lysand/Object";
import type { Attachment as APIAttachment } from "~types/mastodon/attachment";
import type { Status as APIStatus } from "~types/mastodon/status";
@ -601,7 +603,11 @@ export const resolveStatus = async (
for (const attachment of note.attachments ?? []) {
const resolvedAttachment = await attachmentFromLysand(attachment).catch(
(e) => {
console.error(e);
dualLogger.logError(
LogLevel.ERROR,
"Federation.StatusResolver",
e,
);
return null;
},
);
@ -616,7 +622,7 @@ export const resolveStatus = async (
for (const emoji of note.extensions?.["org.lysand:custom_emojis"]?.emojis ??
[]) {
const resolvedEmoji = await fetchEmoji(emoji).catch((e) => {
console.error(e);
dualLogger.logError(LogLevel.ERROR, "Federation.StatusResolver", e);
return null;
});
@ -1010,8 +1016,14 @@ export const federateStatus = async (status: StatusWithRelations) => {
const response = await fetch(request);
if (!response.ok) {
console.error(await response.text());
throw new Error(
dualLogger.log(
LogLevel.DEBUG,
"Federation.Status",
await response.text(),
);
dualLogger.log(
LogLevel.ERROR,
"Federation.Status",
`Failed to federate status ${status.id} to ${user.uri}`,
);
}

View file

@ -12,6 +12,8 @@ import {
relationship,
user,
} from "~drizzle/schema";
import { dualLogger } from "@loggers";
import { LogLevel } from "~packages/log-manager";
import type { Account as APIAccount } from "~types/mastodon/account";
import type { Source as APISource } from "~types/mastodon/source";
import {
@ -191,8 +193,15 @@ export const followRequestUser = async (
const response = await fetch(request);
if (!response.ok) {
console.error(await response.text());
console.error(
dualLogger.log(
LogLevel.DEBUG,
"Federation.FollowRequest",
await response.text(),
);
dualLogger.log(
LogLevel.ERROR,
"Federation.FollowRequest",
`Failed to federate follow request from ${follower.id} to ${followee.uri}`,
);
@ -230,8 +239,15 @@ export const sendFollowAccept = async (follower: User, followee: User) => {
const response = await fetch(request);
if (!response.ok) {
console.error(await response.text());
throw new Error(
dualLogger.log(
LogLevel.DEBUG,
"Federation.FollowAccept",
await response.text(),
);
dualLogger.log(
LogLevel.ERROR,
"Federation.FollowAccept",
`Failed to federate follow accept from ${followee.id} to ${follower.uri}`,
);
}
@ -249,8 +265,15 @@ export const sendFollowReject = async (follower: User, followee: User) => {
const response = await fetch(request);
if (!response.ok) {
console.error(await response.text());
throw new Error(
dualLogger.log(
LogLevel.DEBUG,
"Federation.FollowReject",
await response.text(),
);
dualLogger.log(
LogLevel.ERROR,
"Federation.FollowReject",
`Failed to federate follow reject from ${followee.id} to ${follower.uri}`,
);
}