Skip to content

Commit

Permalink
fix(Nextcloud Node): Throw an actual error if server responded with F…
Browse files Browse the repository at this point in the history
…atal error (n8n-io#8234)

## Summary
Nextcloud and Yourls receiving response with OK status as string
containing 'Fatal error', throw an actual error in such case

![image](https://github.com/n8n-io/n8n/assets/88898367/7cba4b8c-3b34-476f-8a35-e10738022427)

## Related tickets and issues

https://linear.app/n8n/issue/NODE-1035/nextcloud-and-yourls-throw-an-actual-error-if-server-responded-with
  • Loading branch information
michael-radency authored Jan 5, 2024
1 parent 6e78d23 commit b201ff8
Show file tree
Hide file tree
Showing 3 changed files with 2,412 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/nodes-base/nodes/NextCloud/GenericFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IExecuteFunctions, IHookFunctions } from 'n8n-workflow';
import { NodeOperationError, type IExecuteFunctions, type IHookFunctions } from 'n8n-workflow';

import type { OptionsWithUri } from 'request';

Expand Down Expand Up @@ -52,5 +52,18 @@ export async function nextCloudApiRequest(

const credentialType =
authenticationMethod === 'accessToken' ? 'nextCloudApi' : 'nextCloudOAuth2Api';
return this.helpers.requestWithAuthentication.call(this, credentialType, options);

const response = await this.helpers.requestWithAuthentication.call(this, credentialType, options);

if (typeof response === 'string' && response.includes('<b>Fatal error</b>')) {
throw new NodeOperationError(
this.getNode(),
"NextCloud responded with a 'Fatal error', check description for more details",
{
description: `Server response:\n${response}`,
},
);
}

return response;
}
10 changes: 10 additions & 0 deletions packages/nodes-base/nodes/Yourls/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export async function yourlsApiRequest(
);
}

if (typeof response === 'string' && response.includes('<b>Fatal error</b>')) {
throw new NodeOperationError(
this.getNode(),
"Yourls responded with a 'Fatal error', check description for more details",
{
description: `Server response:\n${response}`,
},
);
}

return response;
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
Expand Down
Loading

0 comments on commit b201ff8

Please sign in to comment.