Browse Source

Merge pull request #7025 from nocodb/refactor/6986-uniform-error-message

refactor: Uniform error message
pull/6996/head
Pranav C 1 year ago committed by GitHub
parent
commit
cd5d2390a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 4
      packages/nocodb/src/db/conditionV2.ts
  3. 2
      packages/nocodb/src/db/generateLookupSelectQuery.ts
  4. 4
      packages/nocodb/src/db/sortV2.ts
  5. 2
      packages/nocodb/src/helpers/catchError.ts
  6. 4
      packages/nocodb/src/helpers/getAst.ts

6
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -5194,9 +5194,7 @@ export function extractSortsObject(
else sort.fk_column_id = aliasColObjMap[s.replace(/^\+/, '')]?.id; else sort.fk_column_id = aliasColObjMap[s.replace(/^\+/, '')]?.id;
if (throwErrorIfInvalid && !sort.fk_column_id) if (throwErrorIfInvalid && !sort.fk_column_id)
NcError.unprocessableEntity( NcError.unprocessableEntity(`Invalid field: ${s.replace(/^[+-]/, '')}`);
`Invalid column '${s.replace(/^[+-]/, '')}' in sort`,
);
return new Sort(sort); return new Sort(sort);
}); });
@ -5360,7 +5358,7 @@ export function extractCondition(
validateFilterComparison(aliasColObjMap[alias].uidt, op, sub_op); validateFilterComparison(aliasColObjMap[alias].uidt, op, sub_op);
} else if (throwErrorIfInvalid) { } else if (throwErrorIfInvalid) {
NcError.unprocessableEntity(`Column '${alias}' not found.`); NcError.unprocessableEntity(`Invalid field: ${alias}`);
} }
return new Filter({ return new Filter({

4
packages/nocodb/src/db/conditionV2.ts

@ -155,9 +155,7 @@ const parseConditionV2 = async (
const column = await filter.getColumn(); const column = await filter.getColumn();
if (!column) { if (!column) {
if (throwErrorIfInvalid) { if (throwErrorIfInvalid) {
NcError.unprocessableEntity( NcError.unprocessableEntity(`Invalid field: ${filter.fk_column_id}`);
`Invalid column id '${filter.fk_column_id}' in filter`,
);
} }
return; return;
} }

2
packages/nocodb/src/db/generateLookupSelectQuery.ts

@ -54,7 +54,7 @@ export default async function generateLookupSelectQuery({
if (column.uidt === UITypes.Lookup) { if (column.uidt === UITypes.Lookup) {
lookupColOpt = await column.getColOptions<LookupColumn>(); lookupColOpt = await column.getColOptions<LookupColumn>();
} else if (column.uidt !== UITypes.LinkToAnotherRecord) { } else if (column.uidt !== UITypes.LinkToAnotherRecord) {
NcError.badRequest('Invalid column type'); NcError.badRequest('Invalid field type');
} }
await column.getColOptions<LookupColumn>(); await column.getColOptions<LookupColumn>();

4
packages/nocodb/src/db/sortV2.ts

@ -36,9 +36,7 @@ export default async function sortV2(
const column = await sort.getColumn(); const column = await sort.getColumn();
if (!column) { if (!column) {
if (throwErrorIfInvalid) { if (throwErrorIfInvalid) {
NcError.unprocessableEntity( NcError.unprocessableEntity(`Invalid field: ${sort.fk_column_id}`);
`Invalid column id '${sort.fk_column_id}' in sort`,
);
} }
continue; continue;
} }

2
packages/nocodb/src/helpers/catchError.ts

@ -324,7 +324,7 @@ export function extractDBError(error): {
/ Invalid object name '(\w+)'./i, / Invalid object name '(\w+)'./i,
); );
const extractMissingColMatch = error.message.match( const extractMissingColMatch = error.message.match(
/ Invalid column name '(\w+)'./i, / Invalid field: (\w+)./i,
); );
if (extractTableNameMatch && extractTableNameMatch[1]) { if (extractTableNameMatch && extractTableNameMatch[1]) {

4
packages/nocodb/src/helpers/getAst.ts

@ -73,9 +73,7 @@ const getAst = async ({
(f) => !colAliasMap[f] && !aliasColMap[f], (f) => !colAliasMap[f] && !aliasColMap[f],
); );
if (invalidFields.length) { if (invalidFields.length) {
NcError.unprocessableEntity( NcError.unprocessableEntity(`Invalid field: ${invalidFields[0]}`);
`Following fields are invalid: ${invalidFields.join(', ')}`,
);
} }
} }
} else { } else {

Loading…
Cancel
Save