From 9bf51819342c4b80c2898393c46a18a09f06fad2 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 2 Sep 2022 10:52:24 +0800 Subject: [PATCH 1/2] enhancement: add try catch for covering search mismatch type --- .../lib/meta/api/dataApis/dataAliasApis.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts index b982bbc4de..3a9add1377 100644 --- a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts +++ b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts @@ -107,14 +107,20 @@ async function getDataList(model, view: View, req) { listArgs.sortArr = JSON.parse(listArgs.sortArrJson); } catch (e) {} - const data = await nocoExecute( - requestObj, - await baseModel.list(listArgs), - {}, - listArgs - ); - - const count = await baseModel.count(listArgs); + let data = []; + let count = 0; + try { + data = await nocoExecute( + requestObj, + await baseModel.list(listArgs), + {}, + listArgs + ); + count = await baseModel.count(listArgs); + } catch (_) { + // show empty result instead of throwing error here + // e.g. search some text in a numeric field + } return new PagedResponseImpl(data, { ...req.query, From a59eb6e0720877ddc1461923d79a919bd0b8eeda Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 2 Sep 2022 11:20:10 +0800 Subject: [PATCH 2/2] enhancement: add try catch for covering search mismatch type --- .../lib/meta/api/dataApis/dataAliasApis.ts | 2 +- .../src/lib/meta/api/dataApis/dataApis.ts | 22 +++++--- .../lib/meta/api/publicApis/publicDataApis.ts | 51 ++++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts index 3a9add1377..46e7e071ae 100644 --- a/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts +++ b/packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts @@ -117,7 +117,7 @@ async function getDataList(model, view: View, req) { listArgs ); count = await baseModel.count(listArgs); - } catch (_) { + } catch (e) { // show empty result instead of throwing error here // e.g. search some text in a numeric field } diff --git a/packages/nocodb/src/lib/meta/api/dataApis/dataApis.ts b/packages/nocodb/src/lib/meta/api/dataApis/dataApis.ts index c142ae4303..2635478eaa 100644 --- a/packages/nocodb/src/lib/meta/api/dataApis/dataApis.ts +++ b/packages/nocodb/src/lib/meta/api/dataApis/dataApis.ts @@ -452,14 +452,20 @@ async function getDataList(model, view: View, req) { listArgs.sortArr = JSON.parse(listArgs.sortArrJson); } catch (e) {} - const data = await nocoExecute( - requestObj, - await baseModel.list(listArgs), - {}, - listArgs - ); - - const count = await baseModel.count(listArgs); + let data = []; + let count = 0; + try { + data = await nocoExecute( + requestObj, + await baseModel.list(listArgs), + {}, + listArgs + ); + count = await baseModel.count(listArgs); + } catch (e) { + // show empty result instead of throwing error here + // e.g. search some text in a numeric field + } return new PagedResponseImpl(data, { count, diff --git a/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts b/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts index 345bc5e3b8..fb904c6a1c 100644 --- a/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts +++ b/packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts @@ -50,18 +50,25 @@ export async function dataList(req: Request, res: Response) { listArgs.sortArr = JSON.parse(listArgs.sortArrJson); } catch (e) {} - const data = await nocoExecute( - await getAst({ - query: req.query, - model, - view, - }), - await baseModel.list(listArgs), - {}, - listArgs - ); + let data = []; + let count = 0; - const count = await baseModel.count(listArgs); + try { + data = await nocoExecute( + await getAst({ + query: req.query, + model, + view, + }), + await baseModel.list(listArgs), + {}, + listArgs + ); + count = await baseModel.count(listArgs); + } catch (e) { + // show empty result instead of throwing error here + // e.g. search some text in a numeric field + } res.json({ data: new PagedResponseImpl(data, { ...req.query, count }), @@ -198,14 +205,20 @@ async function relDataList(req, res) { extractOnlyPrimaries: true, }); - const data = await nocoExecute( - requestObj, - await baseModel.list(req.query), - {}, - req.query - ); - - const count = await baseModel.count(req.query); + let data = []; + let count = 0; + try { + data = data = await nocoExecute( + requestObj, + await baseModel.list(req.query), + {}, + req.query + ); + count = await baseModel.count(req.query); + } catch (e) { + // show empty result instead of throwing error here + // e.g. search some text in a numeric field + } res.json(new PagedResponseImpl(data, { ...req.query, count })); }