Skip to content

Commit

Permalink
🚸 (nocodb) Clean up error messages
Browse files Browse the repository at this point in the history
Closes #1568
  • Loading branch information
baptisteArno committed Jun 14, 2024
1 parent ff16706 commit 0f2f4d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/forge/blocks/nocodb/actions/createRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { auth } from '../auth'
import ky, { HTTPError } from 'ky'
import { defaultBaseUrl } from '../constants'
import { parseRecordsCreateBody } from '../helpers/parseRecordCreateBody'
import { parseErrorResponse } from '../helpers/parseErrorResponse'

export const createRecord = createAction({
auth,
Expand Down Expand Up @@ -52,7 +53,7 @@ export const createRecord = createAction({
return logs.add({
status: 'error',
description: error.message,
details: await error.response.text(),
details: await parseErrorResponse(error.response),
})
console.error(error)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/nocodb/actions/searchRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
defaultLimitForSearch,
filterOperators,
} from '../constants'
import { parseErrorResponse } from '../helpers/parseErrorResponse'

export const searchRecords = createAction({
auth,
Expand Down Expand Up @@ -127,7 +128,7 @@ export const searchRecords = createAction({
return logs.add({
status: 'error',
description: error.message,
details: await error.response.text(),
details: await parseErrorResponse(error.response),
})
console.error(error)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/nocodb/actions/updateExistingRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { parseSearchParams } from '../helpers/parseSearchParams'
import { convertFilterToWhereClause } from '../helpers/convertFilterToWhereClause'
import { ListTableRecordsResponse } from '../types'
import { parseErrorResponse } from '../helpers/parseErrorResponse'

export const updateExistingRecord = createAction({
auth,
Expand Down Expand Up @@ -94,7 +95,7 @@ export const updateExistingRecord = createAction({
return logs.add({
status: 'error',
description: error.message,
details: await error.response.text(),
details: await parseErrorResponse(error.response),
})
console.error(error)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/forge/blocks/nocodb/helpers/parseErrorResponse.ts
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 0f2f4d2

Please sign in to comment.