chore(fix): fixes sync response not correctly identifying all errors (#2346)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { HttpErrorResponse } from '../Http'
|
||||
import { HttpErrorResponse, getErrorFromErrorResponse } from '../Http'
|
||||
|
||||
export class ClientDisplayableError {
|
||||
constructor(public text: string, public title?: string, public tag?: string) {
|
||||
@@ -14,7 +14,7 @@ export class ClientDisplayableError {
|
||||
}
|
||||
|
||||
static FromNetworkError(error: HttpErrorResponse) {
|
||||
return new ClientDisplayableError(error.data.error.message)
|
||||
return new ClientDisplayableError(getErrorFromErrorResponse(error).message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HttpError } from './HttpError'
|
||||
|
||||
export type HttpErrorResponseBody = {
|
||||
error: HttpError
|
||||
error?: HttpError
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { HttpErrorResponseBody } from './HttpErrorResponseBody'
|
||||
import { HttpResponseMeta } from './HttpResponseMeta'
|
||||
import { HttpHeaders } from './HttpHeaders'
|
||||
import { HttpStatusCode } from './HttpStatusCode'
|
||||
import { HttpError } from './HttpError'
|
||||
|
||||
type AnySuccessRecord = Record<string, unknown> & { error?: never }
|
||||
|
||||
@@ -24,3 +25,14 @@ export type HttpResponse<T = AnySuccessRecord> = HttpErrorResponse | HttpSuccess
|
||||
export function isErrorResponse<T>(response: HttpResponse<T>): response is HttpErrorResponse {
|
||||
return (response.data as HttpErrorResponseBody)?.error != undefined || response.status >= 400
|
||||
}
|
||||
|
||||
export function getErrorFromErrorResponse(response: HttpErrorResponse): HttpError {
|
||||
const embeddedError = response.data.error
|
||||
if (embeddedError) {
|
||||
return embeddedError
|
||||
}
|
||||
|
||||
return {
|
||||
message: 'Unknown error',
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user