mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-25 00:05:29 +00:00
handle mux error message
This commit is contained in:
@@ -113,6 +113,7 @@ function serializeError(err: any) {
|
||||
...err,
|
||||
message: err.message,
|
||||
stack: err.stack,
|
||||
_errorType: err.constructor?.name,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -541,7 +541,27 @@ export class NcErrorBase {
|
||||
});
|
||||
}
|
||||
|
||||
externalError(message: string, args?: NcErrorArgs): never {
|
||||
// for nc-sql-executor, the error returned is possible to be an Error object
|
||||
// thus `error.message` is needed to access it
|
||||
externalError(error: string | Error, args?: NcErrorArgs): never {
|
||||
let message: string = '';
|
||||
if (['string'].includes(typeof error)) {
|
||||
message = `${error}`;
|
||||
} else if (typeof error === 'object') {
|
||||
if (error.message) {
|
||||
message = error.message;
|
||||
} else {
|
||||
// we log the error if we don't know the schema yet
|
||||
console.log(
|
||||
`Unknown error schema from nc-sql-executor: ${JSON.stringify(error)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!message || message === '') {
|
||||
// generic error message to prevent programmatic error to propagate to UI
|
||||
message =
|
||||
'Error when executing query in external data source, please contact administration to solve this issue';
|
||||
}
|
||||
throw this.errorCodex.generateError(
|
||||
NcErrorType.ERR_IN_EXTERNAL_DATA_SOURCE,
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { DBErrorExtractor } from '~/helpers/db-error/extractor';
|
||||
import { NcError } from '~/helpers/catchError';
|
||||
|
||||
const logger = new Logger('MuxHelpers');
|
||||
@@ -35,7 +36,17 @@ export async function runExternal(
|
||||
return data;
|
||||
} catch (e) {
|
||||
if (e.response?.data?.error) {
|
||||
NcError._.externalError(e.response.data.error);
|
||||
const { _errorType } = e.response.data.error;
|
||||
if (_errorType !== 'DatabaseError') {
|
||||
NcError._.externalError(e.response.data.error);
|
||||
} else {
|
||||
NcError._.externalError(
|
||||
DBErrorExtractor.get().extractDbError(e.response.data.error, {
|
||||
clientType: config.client,
|
||||
ignoreDefault: false,
|
||||
}) as any as Error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (e?.message.includes('timeout')) {
|
||||
|
||||
@@ -156,6 +156,11 @@ export class MysqlDBErrorExtractor implements IClientDbErrorExtractor {
|
||||
message = 'Query returned too many rows.';
|
||||
break;
|
||||
default:
|
||||
this.option.dbErrorLogger.error(
|
||||
`${error.code} is not handled on database mysql`,
|
||||
);
|
||||
message = `An error occured when querying mysql database.`;
|
||||
httpStatus = 500;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,11 @@ export class PgDBErrorExtractor implements IClientDbErrorExtractor {
|
||||
httpStatus = 503;
|
||||
break;
|
||||
default:
|
||||
this.option.dbErrorLogger.error(
|
||||
`${error.code} is not handled on database pg`,
|
||||
);
|
||||
message = `An error occured when querying postgresql database.`;
|
||||
httpStatus = 500;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +119,11 @@ export class SqliteDBErrorExtractor implements IClientDbErrorExtractor {
|
||||
break;
|
||||
|
||||
default:
|
||||
this.option.dbErrorLogger.error(
|
||||
`${error.code} is not handled on database sqlite`,
|
||||
);
|
||||
message = `An error occured when querying sqlite database.`;
|
||||
httpStatus = 500;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user