1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Chore/fix worker request error message (#12943)

* Revert "Surface email error (#12837)"

This reverts commit 2a24c85378.

* Improve workerRequest error handling

* update account portal

* Fix typing

* lint
This commit is contained in:
melohagan 2024-02-02 15:25:18 +00:00 committed by GitHub
parent ca32e1280c
commit be0ff766f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 16 deletions

@ -1 +1 @@
Subproject commit 52f51dcfb96d3fe58c8cc7a905e7d733f7cd84c2
Subproject commit cc12291732ee902dc832bc7d93cf2086ffdf0cff

View file

@ -1,4 +1,4 @@
import fetch from "node-fetch"
import { Response, default as fetch } from "node-fetch"
import env from "../environment"
import { checkSlashesInUrl } from "./index"
import {
@ -40,25 +40,21 @@ export function request(ctx?: Ctx, request?: any) {
}
async function checkResponse(
response: any,
response: Response,
errorMsg: string,
{ ctx }: { ctx?: Ctx } = {}
) {
if (response.status !== 200) {
let error
try {
error = await response.json()
if (!error.message) {
error = JSON.stringify(error)
}
} catch (err) {
error = await response.text()
if (response.status >= 300) {
let responseErrorMessage
if (response.headers.get("content-type")?.includes("json")) {
const error = await response.json()
responseErrorMessage = error.message ?? JSON.stringify(error)
} else {
responseErrorMessage = await response.text()
}
const msg = `Unable to ${errorMsg} - ${
error.message ? error.message : error
}`
const msg = `Unable to ${errorMsg} - ${responseErrorMessage}`
if (ctx) {
ctx.throw(400, msg)
ctx.throw(msg, response.status)
} else {
throw msg
}