fix(admin-next, utils, medusa): Handle db errors properly and fix form (#7416)

* fix(admin-next, utils, medusa): Handle db errors properly and fix form

* fix(admin-next, utils, medusa): Handle db errors properly and fix form

* fix(admin-next, utils, medusa): Handle db errors properly and fix form

* fix(admin-next, utils, medusa): Handle db errors properly and fix form
This commit is contained in:
Adrien de Peretti
2024-05-23 12:36:45 +02:00
committed by GitHub
parent e01472aae6
commit 37ae87fe9b
6 changed files with 47 additions and 14 deletions
+9 -3
View File
@@ -45,8 +45,12 @@ const normalizeRequest = (
const normalizeResponse = async (resp: Response, reqHeaders: Headers) => {
if (resp.status >= 300) {
const error = new FetchError(resp.statusText, resp.status)
throw error
const jsonError = await resp.json().catch(() => ({})) as { message?: string }
throw new FetchError(
jsonError.message ?? resp.statusText,
resp.statusText,
resp.status
)
}
// If we requested JSON, we try to parse the response. Otherwise, we return the raw response.
@@ -56,9 +60,11 @@ const normalizeResponse = async (resp: Response, reqHeaders: Headers) => {
export class FetchError extends Error {
status: number | undefined
statusText: string | undefined
constructor(message: string, status?: number) {
constructor(message: string, statusText?: string, status?: number) {
super(message)
this.statusText = statusText
this.status = status
}
}