Skip to content

Commit

Permalink
Better normalizeMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Nov 24, 2024
1 parent 715ef4d commit b01eb12
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/denops/runtime/functions/denops/request_async_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,22 @@ testHost({
);
});

type ErrorEvent = {
message: string;
name: string;
};
const normalizeMessage = (events: unknown[]) => {
const normalizeMessage = (events: unknown[]): unknown[] => {
return events.map(event => {
const error = (event as unknown[])[1] as ErrorEvent[];
if (error[0]?.message) {
error[0].message = error[0].message.replace(/\n.*/g, '');
if (!Array.isArray(event) || event.length < 2) {
return event;
}
const errors = event[1];
if (!Array.isArray(errors) || errors.length === 0) {
return event;
}
return event;
return [
event[0],
errors.map(error => ({
...error,
message: error?.message?.replace(/\n.*/g, '') ?? error?.message
}))
];
});
};

Expand Down

0 comments on commit b01eb12

Please sign in to comment.