feat: Draft implementation to store and expose integration errors

This commit is contained in:
Faruk AYDIN
2022-09-19 12:13:36 +03:00
parent d0bcf997fb
commit 8826125845
3 changed files with 47 additions and 21 deletions

View File

@@ -19,7 +19,13 @@ export default class SearchTweets {
}; };
let response; let response;
const tweets: IJSONObject[] = []; const tweets: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};
do { do {
const params: IJSONObject = { const params: IJSONObject = {
@@ -47,10 +53,15 @@ export default class SearchTweets {
headers: { ...authHeader }, headers: { ...authHeader },
}); });
if (response.automatischError) {
tweets.error = response.automatischError;
return tweets;
}
if (response.data.meta.result_count > 0) { if (response.data.meta.result_count > 0) {
response.data.data.forEach((tweet: IJSONObject) => { response.data.data.forEach((tweet: IJSONObject) => {
if (!lastInternalId || Number(tweet.id) > Number(lastInternalId)) { if (!lastInternalId || Number(tweet.id) > Number(lastInternalId)) {
tweets.push(tweet); tweets.data.push(tweet);
} else { } else {
return; return;
} }
@@ -58,16 +69,6 @@ export default class SearchTweets {
} }
} while (response.data.meta.next_token && lastInternalId); } while (response.data.meta.next_token && lastInternalId);
if (response.data?.errors) {
const errorMessages = response.data.errors
.map((error: IJSONObject) => error.detail)
.join(' ');
throw new Error(
`Error occured while fetching user data: ${errorMessages}`
);
}
return tweets; return tweets;
} }
} }

View File

@@ -11,7 +11,12 @@ export default class HttpClient {
} }
async get(path: string, options?: IJSONObject) { async get(path: string, options?: IJSONObject) {
return await this.instance.get(path, options); try {
return await this.instance.get(path, options);
} catch (error) {
error.response.automatischError = error.response.data;
return error.response;
}
} }
async post(path: string, body: IJSONObject | string, options?: IJSONObject) { async post(path: string, body: IJSONObject | string, options?: IJSONObject) {

View File

@@ -33,9 +33,9 @@ class Processor {
const triggerStep = steps.find((step) => step.type === 'trigger'); const triggerStep = steps.find((step) => step.type === 'trigger');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
let initialTriggerData = await this.getInitialTriggerData(triggerStep!); const initialTriggerData = await this.getInitialTriggerData(triggerStep!);
if (initialTriggerData.length === 0) { if (!initialTriggerData.error && initialTriggerData.data.length === 0) {
const lastInternalId = await this.flow.lastInternalId(); const lastInternalId = await this.flow.lastInternalId();
const executionData: Partial<Execution> = { const executionData: Partial<Execution> = {
@@ -52,12 +52,12 @@ class Processor {
return; return;
} }
if (this.testRun) { if (this.testRun && initialTriggerData.data.length > 0) {
initialTriggerData = [initialTriggerData[0]]; initialTriggerData.data = [initialTriggerData.data[0]];
} }
if (initialTriggerData.length > 1) { if (initialTriggerData.data.length > 1) {
initialTriggerData = initialTriggerData.sort( initialTriggerData.data = initialTriggerData.data.sort(
(item: IJSONObject, nextItem: IJSONObject) => { (item: IJSONObject, nextItem: IJSONObject) => {
return (item.id as number) - (nextItem.id as number); return (item.id as number) - (nextItem.id as number);
} }
@@ -66,7 +66,7 @@ class Processor {
const executions: Execution[] = []; const executions: Execution[] = [];
for await (const data of initialTriggerData) { for await (const data of initialTriggerData.data) {
const execution = await Execution.query().insert({ const execution = await Execution.query().insert({
flowId: this.flow.id, flowId: this.flow.id,
testRun: this.testRun, testRun: this.testRun,
@@ -118,6 +118,22 @@ class Processor {
} }
} }
if (initialTriggerData.error) {
const executionWithError = await Execution.query().insert({
flowId: this.flow.id,
testRun: this.testRun,
});
executions.push(executionWithError);
await executionWithError.$relatedQuery('executionSteps').insertAndFetch({
stepId: triggerStep.id,
status: 'failure',
dataIn: triggerStep.parameters,
errorDetails: initialTriggerData.error,
});
}
if (!this.testRun) return; if (!this.testRun) return;
const lastExecutionStepFromFirstExecution = await executions[0] const lastExecutionStepFromFirstExecution = await executions[0]
@@ -125,7 +141,11 @@ class Processor {
.orderBy('created_at', 'desc') .orderBy('created_at', 'desc')
.first(); .first();
return lastExecutionStepFromFirstExecution?.dataOut; if (lastExecutionStepFromFirstExecution.errorDetails) {
return lastExecutionStepFromFirstExecution.errorDetails;
} else {
return lastExecutionStepFromFirstExecution?.dataOut;
}
} }
async getInitialTriggerData(step: Step) { async getInitialTriggerData(step: Step) {