Merge branch 'master' of github.com:Budibase/budibase
This commit is contained in:
commit
bc35d6db44
|
@ -1 +1 @@
|
||||||
Subproject commit 52f51dcfb96d3fe58c8cc7a905e7d733f7cd84c2
|
Subproject commit cc12291732ee902dc832bc7d93cf2086ffdf0cff
|
|
@ -1,4 +1,4 @@
|
||||||
import fetch from "node-fetch"
|
import { Response, default as fetch } from "node-fetch"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { checkSlashesInUrl } from "./index"
|
import { checkSlashesInUrl } from "./index"
|
||||||
import {
|
import {
|
||||||
|
@ -40,25 +40,21 @@ export function request(ctx?: Ctx, request?: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkResponse(
|
async function checkResponse(
|
||||||
response: any,
|
response: Response,
|
||||||
errorMsg: string,
|
errorMsg: string,
|
||||||
{ ctx }: { ctx?: Ctx } = {}
|
{ ctx }: { ctx?: Ctx } = {}
|
||||||
) {
|
) {
|
||||||
if (response.status !== 200) {
|
if (response.status >= 300) {
|
||||||
let error
|
let responseErrorMessage
|
||||||
try {
|
if (response.headers.get("content-type")?.includes("json")) {
|
||||||
error = await response.json()
|
const error = await response.json()
|
||||||
if (!error.message) {
|
responseErrorMessage = error.message ?? JSON.stringify(error)
|
||||||
error = JSON.stringify(error)
|
} else {
|
||||||
}
|
responseErrorMessage = await response.text()
|
||||||
} catch (err) {
|
|
||||||
error = await response.text()
|
|
||||||
}
|
}
|
||||||
const msg = `Unable to ${errorMsg} - ${
|
const msg = `Unable to ${errorMsg} - ${responseErrorMessage}`
|
||||||
error.message ? error.message : error
|
|
||||||
}`
|
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
ctx.throw(400, msg)
|
ctx.throw(msg, response.status)
|
||||||
} else {
|
} else {
|
||||||
throw msg
|
throw msg
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue