(error: unknown, status: number)
| 177 | } |
| 178 | |
| 179 | function errorJSON(error: unknown, status: number): Response { |
| 180 | const message = error instanceof Error ? error.message : String(error); |
| 181 | return new Response(JSON.stringify({ error: message }), { |
| 182 | status, |
| 183 | headers: { "content-type": "application/json" }, |
| 184 | }); |
| 185 | } |
| 186 | |
| 187 | // Decode a base64 string to bytes. atob is available in the Workers |
| 188 | // runtime; map each character to its byte value. |