mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
fix(federation): 🐛 Fix some errors not being ignored properly
This commit is contained in:
parent
db2d582295
commit
1216e278e8
4 changed files with 29 additions and 14 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue