diff --git a/packages/forge/blocks/nocodb/actions/createRecord.ts b/packages/forge/blocks/nocodb/actions/createRecord.ts index a8dab529fe..e7bfa9a2e4 100644 --- a/packages/forge/blocks/nocodb/actions/createRecord.ts +++ b/packages/forge/blocks/nocodb/actions/createRecord.ts @@ -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, @@ -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) } diff --git a/packages/forge/blocks/nocodb/actions/searchRecords.ts b/packages/forge/blocks/nocodb/actions/searchRecords.ts index c60f4fba6a..f74a904c7c 100644 --- a/packages/forge/blocks/nocodb/actions/searchRecords.ts +++ b/packages/forge/blocks/nocodb/actions/searchRecords.ts @@ -10,6 +10,7 @@ import { defaultLimitForSearch, filterOperators, } from '../constants' +import { parseErrorResponse } from '../helpers/parseErrorResponse' export const searchRecords = createAction({ auth, @@ -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) } diff --git a/packages/forge/blocks/nocodb/actions/updateExistingRecord.ts b/packages/forge/blocks/nocodb/actions/updateExistingRecord.ts index 563cc6617f..82cdcc4538 100644 --- a/packages/forge/blocks/nocodb/actions/updateExistingRecord.ts +++ b/packages/forge/blocks/nocodb/actions/updateExistingRecord.ts @@ -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, @@ -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) } diff --git a/packages/forge/blocks/nocodb/helpers/parseErrorResponse.ts b/packages/forge/blocks/nocodb/helpers/parseErrorResponse.ts new file mode 100644 index 0000000000..f4a3990cca --- /dev/null +++ b/packages/forge/blocks/nocodb/helpers/parseErrorResponse.ts @@ -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() +}