mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
🐛 Fixes issue handling error responses in Rocketchat node (#1367)
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
export async function rocketchatApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, operation: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function rocketchatApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, resource: string, method: string, operation: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('rocketchatApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
@@ -29,13 +31,15 @@ export async function rocketchatApiRequest(this: IHookFunctions | IExecuteFuncti
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
let errorMessage = error.message;
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
if (error.response.body.error) {
|
||||
errorMessage = error.response.body.error;
|
||||
const errorMessage = error.response.body.error;
|
||||
// Try to return the error prettier
|
||||
throw new Error(
|
||||
`Rocketchat error response [${error.statusCode}]: ${errorMessage}`,
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(`Rocket.chat error response [${error.statusCode}]: ${errorMessage}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user