Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/FileMaker/FileMaker.node.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"node": "n8n-nodes-base.filemaker",
"nodeVersion": "1.0",
"nodeVersion": "1.1",
Joffcom marked this conversation as resolved.
Show resolved Hide resolved
"codexVersion": "1.0",
"categories": ["Development", "Data & Storage"],
"resources": {
Expand Down
10 changes: 5 additions & 5 deletions packages/nodes-base/nodes/FileMaker/FileMaker.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,11 @@ export class FileMaker implements INodeType {
const credentials = await this.getCredentials('fileMaker');

let token;

try {
token = await getToken.call(this);
} catch (error) {
throw new NodeOperationError(this.getNode(), new Error('Login fail', { cause: error }));
throw new NodeOperationError(this.getNode(), error as string);
}

let requestOptions: OptionsWithUri;
Expand Down Expand Up @@ -818,21 +819,19 @@ export class FileMaker implements INodeType {
try {
response = await this.helpers.request(requestOptions);
} catch (error) {
response = error.response.body;
response = error.error;
}

if (typeof response === 'string') {
throw new NodeOperationError(
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 },
);
}
returnData.push({ json: response });
}
} catch (error) {
await logout.call(this, token as string);

if (error.node) {
throw error;
}
Expand All @@ -843,6 +842,7 @@ export class FileMaker implements INodeType {
);
}

await logout.call(this, token as string);
return this.prepareOutputData(returnData);
}
}
34 changes: 13 additions & 21 deletions packages/nodes-base/nodes/FileMaker/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,22 @@ export async function getToken(
if (typeof response === 'string') {
throw new NodeOperationError(
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;
} 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);
}
}

Expand Down Expand Up @@ -257,25 +266,8 @@ export async function logout(
//rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false) as boolean,
};

try {
const response = await this.helpers.request(requestOptions);

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;
}
const response = await this.helpers.request(requestOptions);
return response
}

export function parseSort(this: IExecuteFunctions, i: number): object | null {
Expand Down