refactor: Improve error logging/reporting for cli (#4691)

* use response error classes instead of `ResponseError` everywhere

* improve error logging in dev mode or when telemetry is disabled
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2022-11-22 14:00:36 +01:00
committed by GitHub
parent 5364e7fc92
commit 0b754a4f85
29 changed files with 253 additions and 393 deletions

View File

@@ -157,7 +157,6 @@ import { WaitTracker, WaitTrackerClass } from '@/WaitTracker';
import * as WebhookHelpers from '@/WebhookHelpers';
import * as WebhookServer from '@/WebhookServer';
import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData';
import { ResponseError } from '@/ResponseHelper';
import { toHttpNodeParameters } from '@/CurlConverterHelper';
import { setupErrorMiddleware } from '@/ErrorReporting';
import { getLicense } from '@/License';
@@ -725,7 +724,7 @@ class App {
// eslint-disable-next-line consistent-return
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
if (!Db.isInitialized) {
const error = new ResponseHelper.ResponseError('Database is not ready!', undefined, 503);
const error = new ResponseHelper.ServiceUnavailableError('Database is not ready!');
return ResponseHelper.sendErrorResponse(res, error);
}
@@ -766,7 +765,7 @@ class App {
} catch (err) {
ErrorReporter.error(err);
LoggerProxy.error('No Database connection!', err);
const error = new ResponseHelper.ResponseError('No Database connection!', undefined, 503);
const error = new ResponseHelper.ServiceUnavailableError('No Database connection!');
return ResponseHelper.sendErrorResponse(res, error);
}
@@ -869,7 +868,9 @@ class App {
const { path, methodName } = req.query;
if (!req.query.currentNodeParameters) {
throw new ResponseError('Parameter currentNodeParameters is required.', undefined, 400);
throw new ResponseHelper.BadRequestError(
'Parameter currentNodeParameters is required.',
);
}
const currentNodeParameters = jsonParse(
@@ -904,7 +905,7 @@ class App {
);
}
throw new ResponseError('Parameter methodName is required.', undefined, 400);
throw new ResponseHelper.BadRequestError('Parameter methodName is required.');
},
),
);
@@ -1076,10 +1077,8 @@ class App {
userId: req.user.id,
});
throw new ResponseHelper.ResponseError(
throw new ResponseHelper.BadRequestError(
`Workflow with ID "${workflowId}" could not be found.`,
undefined,
400,
);
}
@@ -1103,7 +1102,7 @@ class App {
const parameters = toHttpNodeParameters(curlCommand);
return ResponseHelper.flattenObject(parameters, 'parameters');
} catch (e) {
throw new ResponseHelper.ResponseError(`Invalid cURL command`, undefined, 400);
throw new ResponseHelper.BadRequestError(`Invalid cURL command`);
}
},
),
@@ -1178,11 +1177,7 @@ class App {
if (!credentialId) {
LoggerProxy.error('OAuth1 credential authorization failed due to missing credential ID');
throw new ResponseHelper.ResponseError(
'Required credential ID is missing',
undefined,
400,
);
throw new ResponseHelper.BadRequestError('Required credential ID is missing');
}
const credential = await getCredentialForUser(credentialId, req.user);
@@ -1192,18 +1187,14 @@ class App {
'OAuth1 credential authorization failed because the current user does not have the correct permissions',
{ userId: req.user.id },
);
throw new ResponseHelper.ResponseError(
RESPONSE_ERROR_MESSAGES.NO_CREDENTIAL,
undefined,
404,
);
throw new ResponseHelper.NotFoundError(RESPONSE_ERROR_MESSAGES.NO_CREDENTIAL);
}
let encryptionKey: string;
try {
encryptionKey = await UserSettings.getEncryptionKey();
} catch (error) {
throw new ResponseHelper.ResponseError(error.message, undefined, 500);
throw new ResponseHelper.InternalServerError(error.message);
}
const mode: WorkflowExecuteMode = 'internal';
@@ -1304,12 +1295,10 @@ class App {
const { oauth_verifier, oauth_token, cid: credentialId } = req.query;
if (!oauth_verifier || !oauth_token) {
const errorResponse = new ResponseHelper.ResponseError(
const errorResponse = new ResponseHelper.ServiceUnavailableError(
`Insufficient parameters for OAuth1 callback. Received following query parameters: ${JSON.stringify(
req.query,
)}`,
undefined,
503,
);
LoggerProxy.error(
'OAuth1 callback failed because of insufficient parameters received',
@@ -1328,10 +1317,8 @@ class App {
userId: req.user?.id,
credentialId,
});
const errorResponse = new ResponseHelper.ResponseError(
const errorResponse = new ResponseHelper.NotFoundError(
RESPONSE_ERROR_MESSAGES.NO_CREDENTIAL,
undefined,
404,
);
return ResponseHelper.sendErrorResponse(res, errorResponse);
}
@@ -1340,7 +1327,7 @@ class App {
try {
encryptionKey = await UserSettings.getEncryptionKey();
} catch (error) {
throw new ResponseHelper.ResponseError(error.message, undefined, 500);
throw new ResponseHelper.InternalServerError(error.message);
}
const mode: WorkflowExecuteMode = 'internal';
@@ -1378,11 +1365,7 @@ class App {
userId: req.user?.id,
credentialId,
});
const errorResponse = new ResponseHelper.ResponseError(
'Unable to get access tokens!',
undefined,
404,
);
const errorResponse = new ResponseHelper.NotFoundError('Unable to get access tokens!');
return ResponseHelper.sendErrorResponse(res, errorResponse);
}
@@ -1539,7 +1522,7 @@ class App {
const sharedWorkflowIds = await getSharedWorkflowIds(req.user);
if (!sharedWorkflowIds.length) {
throw new ResponseHelper.ResponseError('Execution not found', undefined, 404);
throw new ResponseHelper.NotFoundError('Execution not found');
}
const execution = await Db.collections.Execution.findOne({
@@ -1550,7 +1533,7 @@ class App {
});
if (!execution) {
throw new ResponseHelper.ResponseError('Execution not found', undefined, 404);
throw new ResponseHelper.NotFoundError('Execution not found');
}
if (config.getEnv('executions.mode') === 'queue') {