Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): fix error api error message parsing (Issue #1481) #1887

Merged
merged 23 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a0e289a
fix(chat): add error messages for failed publish requests
Jul 29, 2024
c5af348
Merge branch 'development' into fix/1481-error-notifications
Gimir Jul 29, 2024
cb4b42a
Merge branch 'development' into fix/1481-error-notifications
IlyaBondar Jul 30, 2024
e28c616
Merge branch 'development' of https://github.com/epam/ai-dial-chat in…
Jul 31, 2024
17d4715
fix(chat): fix request response wrapper
Jul 31, 2024
eb46fe3
fix(chat): move error parser to ServerUtils
Jul 31, 2024
ef73569
Merge branch 'fix/1481-error-notifications' of https://github.com/epa…
Jul 31, 2024
e7a60ec
Merge branch 'development' into fix/1481-error-notifications
Gimir Jul 31, 2024
b887970
Merge branch 'development' into fix/1481-error-notifications
IlyaBondar Jul 31, 2024
e485f23
Merge branch 'development' into fix/1481-error-notifications
IlyaBondar Aug 1, 2024
1540e93
fix(chat): refactor error message parser
Gimir Aug 1, 2024
8f29d28
fix(chat): run formatters
Aug 1, 2024
1515d23
Merge branch 'development' of https://github.com/epam/ai-dial-chat in…
Aug 6, 2024
ce6edbb
fix(chat): fix api error message parsing
Aug 6, 2024
a1b552a
Merge branch 'development' into fix/1481-error-notifications
Gimir Aug 6, 2024
249f41d
fix(chat): apply response error parser for request
Aug 7, 2024
ebc09ea
Merge branch 'development' into fix/1481-error-notifications
IlyaBondar Aug 7, 2024
447b179
fix(chat): fix error matching in accept invite
Aug 7, 2024
fe45155
Merge branch 'development' into fix/1481-error-notifications
Gimir Aug 8, 2024
0d39ae4
fix(chat): pass status text as error message in share proxy
Aug 8, 2024
14830ec
Merge branch 'development' into fix/1481-error-notifications
Gimir Aug 8, 2024
92d1c25
fix(chat): run format
Aug 8, 2024
33d7c5a
Merge branch 'development' into fix/1481-error-notifications
Gimir Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions apps/chat/src/pages/api/share/accept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
},
);

let json: unknown;
if (!proxyRes.ok) {
try {
json = await proxyRes.json();
} catch (err) {
json = undefined;
}

throw new DialAIError(
(typeof json === 'string' && json) || proxyRes.statusText,
'',
'',
proxyRes.status + '',
);
throw new DialAIError(proxyRes.statusText, '', '', proxyRes.status + '');
}

return res.status(200).send(JSON.stringify({}));
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/store/share/share.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ const acceptInvitationEpic: AppEpic = (action$) =>
catchError((err) => {
console.error(err);
let message = errorsMessages.acceptShareFailed;
if (err.message === '404') {
if (err.message.trim().toLowerCase() === 'not found') {
message = errorsMessages.acceptShareNotExists;
}
return of(ShareActions.acceptShareInvitationFail({ message }));
Expand Down
15 changes: 9 additions & 6 deletions apps/chat/src/utils/server/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Observable, catchError, from, switchMap, throwError } from 'rxjs';
import { Observable, from, switchMap, throwError } from 'rxjs';
import { fromFetch } from 'rxjs/fetch';

import { ServerUtils } from '@/src/utils/server/server';

import { Conversation, ConversationInfo } from '@/src/types/chat';
import { PromptInfo } from '@/src/types/prompt';

Expand Down Expand Up @@ -107,11 +109,12 @@ export class ApiUtils {
}).pipe(
switchMap((response) => {
if (!response.ok) {
return from(response.text()).pipe(
switchMap((errorMessage) =>
throwError(() => new Error(errorMessage)),
),
catchError(() => throwError(() => new Error(response.status + ''))),
return from(ServerUtils.getErrorMessageFromResponse(response)).pipe(
switchMap((errorMessage) => {
return throwError(
() => new Error(errorMessage || response.status + ''),
);
}),
);
}

Expand Down
14 changes: 8 additions & 6 deletions apps/chat/src/utils/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextApiRequest } from 'next';
import { constructPath } from '../app/file';
import { ApiUtils } from './api';

import { Response } from 'node-fetch';
import { Response as NodeFetchResponse } from 'node-fetch';

export class ServerUtils {
public static getEntityTypeFromPath = (
Expand All @@ -20,16 +20,18 @@ export class ServerUtils {
);

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