Skip to content

Commit

Permalink
fix(chat): fix overflowing long message in error toast (Issue #1915) (#…
Browse files Browse the repository at this point in the history
…1935)

Co-authored-by: Magomed-Elbi Dzhukalaev <[email protected]>
  • Loading branch information
Gimir and Magomed-Elbi Dzhukalaev authored Aug 15, 2024
1 parent b24eca3 commit 425e7c4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions apps/chat/src/utils/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@ export class ServerUtils {
.map((part) => ApiUtils.safeEncodeURIComponent(part as string)),
);

public static safeDecodeURI = (str: string): string => {
try {
return decodeURIComponent(str);
} catch {
return str;
}
};

public static getErrorMessageFromResponse = async (
res: Response | NodeFetchResponse,
): Promise<string | null> => {
try {
const text = await res.text();
try {
const json = JSON.parse(text);
return typeof json === 'string' ? json : JSON.stringify(json);
return this.safeDecodeURI(
typeof json === 'string' ? json : JSON.stringify(json),
);
} catch {
return text;
return this.safeDecodeURI(text);
}
} catch {
return null;
Expand Down

0 comments on commit 425e7c4

Please sign in to comment.