Skip to content

Commit

Permalink
🔊 (difyAi) Improve error handling in createChatMessage action
Browse files Browse the repository at this point in the history
Related to #1892
  • Loading branch information
baptisteArno committed Nov 23, 2024
1 parent 6088a56 commit a37cdb3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/forge/blocks/difyAi/src/actions/createChatMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createAction, option } from "@typebot.io/forge";
import { stringifyError } from "@typebot.io/lib/stringifyError";
import { isDefined, isEmpty, isNotEmpty } from "@typebot.io/lib/utils";
import { formatStreamPart } from "ai";
import ky, { HTTPError } from "ky";
Expand Down Expand Up @@ -108,7 +109,13 @@ export const createChatMessage = createAction({
);
const reader = response.body?.getReader();

if (!reader) return {};
if (!reader)
return {
httpError: {
status: 500,
message: "Could not get reader from Dify response",
},
};

return {
stream: new ReadableStream({
Expand Down Expand Up @@ -172,7 +179,12 @@ export const createChatMessage = createAction({
};
}
console.error(err);
return {};
return {
httpError: {
status: 500,
message: stringifyError(err),
},
};
}
},
},
Expand Down Expand Up @@ -297,6 +309,11 @@ export const createChatMessage = createAction({
});
}
console.error(err);
return logs.add({
status: "error",
description: "An unknown error occurred",
details: stringifyError(err),
});
}
},
},
Expand Down

0 comments on commit a37cdb3

Please sign in to comment.