Skip to content

Commit

Permalink
feat: add error handling
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Nov 23, 2023
1 parent b191faa commit 4bcca2a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions server/utils/message_parser_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,32 @@ describe('MessageParserRunner', () => {
},
]);
});

it('Do not append messages that are throwed with error or not an array', async () => {
const messageParserRunner = new MessageParserRunner([
{
id: 'test_with_error',
parserProvider() {
throw new Error('error');
},
},
{
id: 'test_with_incorrect_format_of_return',
parserProvider() {
return Promise.resolve({
type: 'output',
contentType: 'markdown',
content: 'order1000',
});
},
},
]);

expect(
await messageParserRunner.run({
response: 'output',
input: 'input',
})
).toEqual([]);
});
});
6 changes: 6 additions & 0 deletions server/utils/message_parser_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export class MessageParserRunner {
let tempResult: IMessage[] = [];
try {
tempResult = await messageParser.parserProvider(interaction);
/**
* Make sure the tempResult is an array.
*/
if (!Array.isArray(tempResult)) {
tempResult = [];
}
} catch (e) {
tempResult = [];
}
Expand Down

0 comments on commit 4bcca2a

Please sign in to comment.