fix(federation): 🐛 Fix some errors not being ignored properly

This commit is contained in:
Jesse Wierzbinski 2024-07-26 17:20:37 +02:00
parent db2d582295
commit 1216e278e8
No known key found for this signature in database
4 changed files with 29 additions and 14 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -106,13 +106,13 @@
"@json2csv/plainjs": "^7.0.6",
"@logtape/logtape": "npm:@jsr/logtape__logtape@0.4.2",
"@lysand-org/client": "^0.2.5",
"@lysand-org/federation": "^2.1.9",
"@lysand-org/federation": "^2.1.10",
"@oclif/core": "^4.0.14",
"@sentry/bun": "^8.20.0",
"@tufjs/canonical-json": "^2.0.0",
"altcha-lib": "^0.5.1",
"blurhash": "^2.0.5",
"bullmq": "^5.10.3",
"bullmq": "^5.10.4",
"chalk": "^5.3.0",
"cli-progress": "^3.12.0",
"cli-table": "^0.3.11",

View file

@ -2,6 +2,7 @@ import { getLogger } from "@logtape/logtape";
import {
EntityValidator,
FederationRequester,
type ResponseError,
type ValidationError,
} from "@lysand-org/federation";
import type { ServerMetadata } from "@lysand-org/federation/types";
@ -145,7 +146,9 @@ export class Instance extends BaseInterface<typeof Instances> {
// @ts-expect-error Bun extension
proxy: config.http.proxy.address,
},
);
).catch((e) => ({
...(e as ResponseError).response,
}));
if (!(ok && raw.headers.get("content-type")?.includes("json"))) {
// If the server doesn't have a Lysand well-known endpoint, it's not a Lysand instance
@ -202,7 +205,13 @@ export class Instance extends BaseInterface<typeof Instances> {
}>(wellKnownUrl, {
// @ts-expect-error Bun extension
proxy: config.http.proxy.address,
});
}).catch((e) => ({
...(
e as ResponseError<{
links: { rel: string; href: string }[];
}>
).response,
}));
if (!ok) {
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
@ -246,7 +255,19 @@ export class Instance extends BaseInterface<typeof Instances> {
}>(metadataUrl.href, {
// @ts-expect-error Bun extension
proxy: config.http.proxy.address,
});
}).catch((e) => ({
...(
e as ResponseError<{
metadata: {
nodeName?: string;
title?: string;
nodeDescription?: string;
description?: string;
};
software: { version: string };
}>
).response,
}));
if (!ok2) {
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(

View file

@ -340,19 +340,13 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
uri: string,
instance: Instance,
): Promise<User> {
const {
raw: response,
data: json,
ok,
} = await FederationRequester.get<Partial<LysandUser>>(uri, {
const { data: json } = await FederationRequester.get<
Partial<LysandUser>
>(uri, {
// @ts-expect-error Bun extension
proxy: config.http.proxy.address,
});
if (!ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const validator = new EntityValidator();
const data = await validator.User(json);