@@ -3,6 +3,7 @@ import { auth } from '../auth'
|
|||||||
import ky, { HTTPError } from 'ky'
|
import ky, { HTTPError } from 'ky'
|
||||||
import { defaultBaseUrl } from '../constants'
|
import { defaultBaseUrl } from '../constants'
|
||||||
import { parseRecordsCreateBody } from '../helpers/parseRecordCreateBody'
|
import { parseRecordsCreateBody } from '../helpers/parseRecordCreateBody'
|
||||||
|
import { parseErrorResponse } from '../helpers/parseErrorResponse'
|
||||||
|
|
||||||
export const createRecord = createAction({
|
export const createRecord = createAction({
|
||||||
auth,
|
auth,
|
||||||
@@ -52,7 +53,7 @@ export const createRecord = createAction({
|
|||||||
return logs.add({
|
return logs.add({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
description: error.message,
|
description: error.message,
|
||||||
details: await error.response.text(),
|
details: await parseErrorResponse(error.response),
|
||||||
})
|
})
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
defaultLimitForSearch,
|
defaultLimitForSearch,
|
||||||
filterOperators,
|
filterOperators,
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
|
import { parseErrorResponse } from '../helpers/parseErrorResponse'
|
||||||
|
|
||||||
export const searchRecords = createAction({
|
export const searchRecords = createAction({
|
||||||
auth,
|
auth,
|
||||||
@@ -127,7 +128,7 @@ export const searchRecords = createAction({
|
|||||||
return logs.add({
|
return logs.add({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
description: error.message,
|
description: error.message,
|
||||||
details: await error.response.text(),
|
details: await parseErrorResponse(error.response),
|
||||||
})
|
})
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
import { parseSearchParams } from '../helpers/parseSearchParams'
|
import { parseSearchParams } from '../helpers/parseSearchParams'
|
||||||
import { convertFilterToWhereClause } from '../helpers/convertFilterToWhereClause'
|
import { convertFilterToWhereClause } from '../helpers/convertFilterToWhereClause'
|
||||||
import { ListTableRecordsResponse } from '../types'
|
import { ListTableRecordsResponse } from '../types'
|
||||||
|
import { parseErrorResponse } from '../helpers/parseErrorResponse'
|
||||||
|
|
||||||
export const updateExistingRecord = createAction({
|
export const updateExistingRecord = createAction({
|
||||||
auth,
|
auth,
|
||||||
@@ -94,7 +95,7 @@ export const updateExistingRecord = createAction({
|
|||||||
return logs.add({
|
return logs.add({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
description: error.message,
|
description: error.message,
|
||||||
details: await error.response.text(),
|
details: await parseErrorResponse(error.response),
|
||||||
})
|
})
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export const parseErrorResponse = async (res: Response) => {
|
||||||
|
if (res.headers.get('content-type')?.includes('application/json')) {
|
||||||
|
const json = await res.json()
|
||||||
|
if ('msg' in json) return json.msg
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.text()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user