mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-23 14:46:07 +09:00
[backend] Don't treat HTTP 429 errors as non-retryable
This commit is contained in:
parent
447bd10ec0
commit
416dbb5887
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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}`;
|
||||
|
@ -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(
|
||||
|
@ -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}`;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -280,7 +280,7 @@ export async function createNote(
|
||||
} catch (e) {
|
||||
return {
|
||||
status:
|
||||
e instanceof StatusError && e.isClientError
|
||||
e instanceof StatusError && !e.isRetryable
|
||||
? "permerror"
|
||||
: "temperror",
|
||||
};
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user