(
status: number,
code: number,
message: string,
opts?: {
readonly cors?: boolean;
readonly challenge?: string;
readonly retryAfterSeconds?: number;
},
)
| 84 | * local — the four hand-rolled copies are deleted in favor of this. |
| 85 | */ |
| 86 | export const jsonRpcErrorBody = ( |
| 87 | status: number, |
| 88 | code: number, |
| 89 | message: string, |
| 90 | opts?: { |
| 91 | readonly cors?: boolean; |
| 92 | readonly challenge?: string; |
| 93 | readonly retryAfterSeconds?: number; |
| 94 | }, |
| 95 | ): Response => { |
| 96 | const cors = opts?.cors ?? true; |
| 97 | const challenge = opts?.challenge; |
| 98 | const retryAfterSeconds = opts?.retryAfterSeconds; |
| 99 | return new Response(JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id: null }), { |
| 100 | status, |
| 101 | headers: { |
| 102 | "content-type": "application/json", |
| 103 | ...(cors ? { "access-control-allow-origin": "*" } : {}), |
| 104 | ...(challenge |
| 105 | ? { |
| 106 | "www-authenticate": challenge, |
| 107 | "access-control-expose-headers": "WWW-Authenticate", |
| 108 | } |
| 109 | : {}), |
| 110 | ...(retryAfterSeconds === undefined ? {} : { "retry-after": String(retryAfterSeconds) }), |
| 111 | }, |
| 112 | }); |
| 113 | }; |
| 114 | |
| 115 | /** |
| 116 | * Advertised on transient-auth 503s (`Unavailable` outcomes) so clients back |
no outgoing calls
no test coverage detected