mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 20:29:08 +00:00
🎨 Centralize error throwing for encryption keys and credentials (#3105)
* Centralized error throwing for encryption key * Unifying the error message used by cli and core packages * Improvements to error messages to make it more DRY * Removed unnecessary throw * Throwing error when credential does not exist to simplify node behavior (#3112) Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -115,13 +115,15 @@ credentialsController.post(
|
||||
ResponseHelper.send(async (req: CredentialRequest.Test): Promise<INodeCredentialTestResult> => {
|
||||
const { credentials, nodeToTestWith } = req.body;
|
||||
|
||||
const encryptionKey = await UserSettings.getEncryptionKey();
|
||||
|
||||
if (!encryptionKey) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY,
|
||||
};
|
||||
let encryptionKey: string;
|
||||
try {
|
||||
encryptionKey = await UserSettings.getEncryptionKey();
|
||||
} catch (error) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY,
|
||||
undefined,
|
||||
500,
|
||||
);
|
||||
}
|
||||
|
||||
const helper = new CredentialsHelper(encryptionKey);
|
||||
@@ -149,9 +151,10 @@ credentialsController.post(
|
||||
nodeAccess.date = new Date();
|
||||
}
|
||||
|
||||
const encryptionKey = await UserSettings.getEncryptionKey();
|
||||
|
||||
if (!encryptionKey) {
|
||||
let encryptionKey: string;
|
||||
try {
|
||||
encryptionKey = await UserSettings.getEncryptionKey();
|
||||
} catch (error) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY,
|
||||
undefined,
|
||||
@@ -285,9 +288,10 @@ credentialsController.patch(
|
||||
}
|
||||
}
|
||||
|
||||
const encryptionKey = await UserSettings.getEncryptionKey();
|
||||
|
||||
if (!encryptionKey) {
|
||||
let encryptionKey: string;
|
||||
try {
|
||||
encryptionKey = await UserSettings.getEncryptionKey();
|
||||
} catch (error) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY,
|
||||
undefined,
|
||||
@@ -393,9 +397,10 @@ credentialsController.get(
|
||||
|
||||
const { data, id, ...rest } = credential;
|
||||
|
||||
const encryptionKey = await UserSettings.getEncryptionKey();
|
||||
|
||||
if (!encryptionKey) {
|
||||
let encryptionKey: string;
|
||||
try {
|
||||
encryptionKey = await UserSettings.getEncryptionKey();
|
||||
} catch (error) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY,
|
||||
undefined,
|
||||
|
||||
Reference in New Issue
Block a user