[backend] Don't treat HTTP 429 errors as non-retryable
This commit is contained in:
parent
447bd10ec0
commit
416dbb5887
8 changed files with 9 additions and 7 deletions
|
|
@ -194,6 +194,7 @@ export class StatusError extends Error {
|
||||||
public statusCode: number;
|
public statusCode: number;
|
||||||
public statusMessage?: string;
|
public statusMessage?: string;
|
||||||
public isClientError: boolean;
|
public isClientError: boolean;
|
||||||
|
public isRetryable: boolean;
|
||||||
|
|
||||||
constructor(message: string, statusCode: number, statusMessage?: string) {
|
constructor(message: string, statusCode: number, statusMessage?: string) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
@ -204,5 +205,6 @@ export class StatusError extends Error {
|
||||||
typeof this.statusCode === "number" &&
|
typeof this.statusCode === "number" &&
|
||||||
this.statusCode >= 400 &&
|
this.statusCode >= 400 &&
|
||||||
this.statusCode < 500;
|
this.statusCode < 500;
|
||||||
|
this.isRetryable = this.isClientError && this.statusCode != 429;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ async function process(job: Job<DeliverJobData>) {
|
||||||
|
|
||||||
if (res instanceof StatusError) {
|
if (res instanceof StatusError) {
|
||||||
// 4xx
|
// 4xx
|
||||||
if (res.isClientError) {
|
if (!res.isRetryable) {
|
||||||
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり
|
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり
|
||||||
// 何回再送しても成功することはないということなのでエラーにはしないでおく
|
// 何回再送しても成功することはないということなのでエラーにはしないでおく
|
||||||
return `${res.statusCode} ${res.statusMessage}`;
|
return `${res.statusCode} ${res.statusMessage}`;
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ async function process(job: Job<InboxJobData>): Promise<string> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Skip if target is 4xx
|
// Skip if target is 4xx
|
||||||
if (e instanceof StatusError) {
|
if (e instanceof StatusError) {
|
||||||
if (e.isClientError) {
|
if (!e.isRetryable) {
|
||||||
return `skip: Ignored deleted actors on both ends ${activity.actor} - ${e.statusCode}`;
|
return `skip: Ignored deleted actors on both ends ${activity.actor} - ${e.statusCode}`;
|
||||||
}
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ async function process(job: Job<WebhookDeliverJobData>) {
|
||||||
|
|
||||||
if (res instanceof StatusError) {
|
if (res instanceof StatusError) {
|
||||||
// 4xx
|
// 4xx
|
||||||
if (res.isClientError) {
|
if (!res.isRetryable) {
|
||||||
return `${res.statusCode} ${res.statusMessage}`;
|
return `${res.statusCode} ${res.statusMessage}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export default async function (
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Skip if target is 4xx
|
// Skip if target is 4xx
|
||||||
if (e instanceof StatusError) {
|
if (e instanceof StatusError) {
|
||||||
if (e.isClientError) {
|
if (!e.isRetryable) {
|
||||||
logger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`);
|
logger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export default async function (
|
||||||
await createNote(note, resolver, silent);
|
await createNote(note, resolver, silent);
|
||||||
return "ok";
|
return "ok";
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof StatusError && e.isClientError) {
|
if (e instanceof StatusError && !e.isRetryable) {
|
||||||
return `skip ${e.statusCode}`;
|
return `skip ${e.statusCode}`;
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,7 @@ export async function createNote(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
status:
|
status:
|
||||||
e instanceof StatusError && e.isClientError
|
e instanceof StatusError && !e.isRetryable
|
||||||
? "permerror"
|
? "permerror"
|
||||||
: "temperror",
|
: "temperror",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ export default async function (ctx: Koa.Context) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
serverLogger.error(`${e}`);
|
serverLogger.error(`${e}`);
|
||||||
|
|
||||||
if (e instanceof StatusError && e.isClientError) {
|
if (e instanceof StatusError && !e.isRetryable) {
|
||||||
ctx.status = e.statusCode;
|
ctx.status = e.statusCode;
|
||||||
ctx.set("Cache-Control", "max-age=86400");
|
ctx.set("Cache-Control", "max-age=86400");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue