[backend] Don't treat HTTP 429 errors as non-retryable

This commit is contained in:
Laura Hausmann 2024-11-17 16:12:47 +01:00
parent 447bd10ec0
commit 416dbb5887
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
8 changed files with 9 additions and 7 deletions

View File

@ -194,6 +194,7 @@ export class StatusError extends Error {
public statusCode: number;
public statusMessage?: string;
public isClientError: boolean;
public isRetryable: boolean;
constructor(message: string, statusCode: number, statusMessage?: string) {
super(message);
@ -204,5 +205,6 @@ export class StatusError extends Error {
typeof this.statusCode === "number" &&
this.statusCode >= 400 &&
this.statusCode < 500;
this.isRetryable = this.isClientError && this.statusCode != 429;
}
}

View File

@ -75,7 +75,7 @@ async function process(job: Job<DeliverJobData>) {
if (res instanceof StatusError) {
// 4xx
if (res.isClientError) {
if (!res.isRetryable) {
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり
// 何回再送しても成功することはないということなのでエラーにはしないでおく
return `${res.statusCode} ${res.statusMessage}`;

View File

@ -80,7 +80,7 @@ async function process(job: Job<InboxJobData>): Promise<string> {
} catch (e) {
// Skip if target is 4xx
if (e instanceof StatusError) {
if (e.isClientError) {
if (!e.isRetryable) {
return `skip: Ignored deleted actors on both ends ${activity.actor} - ${e.statusCode}`;
}
throw new Error(

View File

@ -58,7 +58,7 @@ async function process(job: Job<WebhookDeliverJobData>) {
if (res instanceof StatusError) {
// 4xx
if (res.isClientError) {
if (!res.isRetryable) {
return `${res.statusCode} ${res.statusMessage}`;
}

View File

@ -48,7 +48,7 @@ export default async function (
} catch (e) {
// Skip if target is 4xx
if (e instanceof StatusError) {
if (e.isClientError) {
if (!e.isRetryable) {
logger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`);
return;
}

View File

@ -40,7 +40,7 @@ export default async function (
await createNote(note, resolver, silent);
return "ok";
} catch (e) {
if (e instanceof StatusError && e.isClientError) {
if (e instanceof StatusError && !e.isRetryable) {
return `skip ${e.statusCode}`;
} else {
throw e;

View File

@ -280,7 +280,7 @@ export async function createNote(
} catch (e) {
return {
status:
e instanceof StatusError && e.isClientError
e instanceof StatusError && !e.isRetryable
? "permerror"
: "temperror",
};

View File

@ -106,7 +106,7 @@ export default async function (ctx: Koa.Context) {
} catch (e) {
serverLogger.error(`${e}`);
if (e instanceof StatusError && e.isClientError) {
if (e instanceof StatusError && !e.isRetryable) {
ctx.status = e.statusCode;
ctx.set("Cache-Control", "max-age=86400");
} else {