fix(FileMaker Node): Improve returned error responses (#6585)

This commit is contained in:
Romain Dunand 2023-07-17 18:05:28 +02:00 committed by GitHub
parent 2acd71eeb1
commit 91a052e4c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 26 deletions

View file

@ -698,10 +698,11 @@ export class FileMaker implements INodeType {
const credentials = await this.getCredentials('fileMaker'); const credentials = await this.getCredentials('fileMaker');
let token; let token;
try { try {
token = await getToken.call(this); token = await getToken.call(this);
} catch (error) { } catch (error) {
throw new NodeOperationError(this.getNode(), new Error('Login fail', { cause: error })); throw new NodeOperationError(this.getNode(), error as string);
} }
let requestOptions: OptionsWithUri; let requestOptions: OptionsWithUri;
@ -818,21 +819,19 @@ export class FileMaker implements INodeType {
try { try {
response = await this.helpers.request(requestOptions); response = await this.helpers.request(requestOptions);
} catch (error) { } catch (error) {
response = error.response.body; response = error.error;
} }
if (typeof response === 'string') { if (typeof response === 'string') {
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), this.getNode(),
'Response body is not valid JSON. Change "Response Format" to "String"', 'DataAPI response body is not valid JSON. Is the DataAPI enabled?',
{ itemIndex: i }, { itemIndex: i },
); );
} }
returnData.push({ json: response }); returnData.push({ json: response });
} }
} catch (error) { } catch (error) {
await logout.call(this, token as string);
if (error.node) { if (error.node) {
throw error; throw error;
} }
@ -843,6 +842,7 @@ export class FileMaker implements INodeType {
); );
} }
await logout.call(this, token as string);
return this.prepareOutputData(returnData); return this.prepareOutputData(returnData);
} }
} }

View file

@ -70,13 +70,22 @@ export async function getToken(
if (typeof response === 'string') { if (typeof response === 'string') {
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), this.getNode(),
'Response body is not valid JSON. Change "Response Format" to "String"', 'DataAPI response body is not valid JSON. Is the DataAPI enabled?',
); );
} }
return response.response.token; return response.response.token;
} catch (error) { } catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject); let message
if ( error.statusCode === 502 ) {
message = 'The server is not responding. Is the DataAPI enabled?'
}
else if (error.error ) {
message = error.error.messages[0].code + ' - ' + error.error.messages[0].message
} else {
message = error.message;
}
throw new Error(message);
} }
} }
@ -257,25 +266,8 @@ export async function logout(
//rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false) as boolean, //rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false) as boolean,
}; };
try { const response = await this.helpers.request(requestOptions);
const response = await this.helpers.request(requestOptions); return response
if (typeof response === 'string') {
throw new NodeOperationError(
this.getNode(),
'Response body is not valid JSON. Change "Response Format" to "String"',
);
}
return response;
} catch (error) {
const errorMessage = `${error.response.body.messages[0].message}'(' + ${error.response.body.messages[0].message}')'`;
if (errorMessage !== undefined) {
throw new Error(errorMessage);
}
throw error.response.body;
}
} }
export function parseSort(this: IExecuteFunctions, i: number): object | null { export function parseSort(this: IExecuteFunctions, i: number): object | null {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 62 KiB