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(api): handle error properly when end system fetch error #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
22 changes: 19 additions & 3 deletions src/routes/articleReader/articleReaderRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ export const articleReaderRouter: Router = (() => {
const { url } = _req.query;

if (typeof url !== 'string') {
return new ServiceResponse(ResponseStatus.Failed, 'URL must be a string', null, StatusCodes.BAD_REQUEST);
const serviceResponse = new ServiceResponse(
ResponseStatus.Failed,
'URL must be a string',
null,
StatusCodes.BAD_REQUEST
);
handleServiceResponse(serviceResponse, res);
return;
}

try {
Expand All @@ -85,10 +92,19 @@ export const articleReaderRouter: Router = (() => {
StatusCodes.OK
);
handleServiceResponse(serviceResponse, res);
return;
} catch (error) {
console.error(`Error fetching content ${(error as Error).message}`);
const errorMessage = `Error fetching content $${(error as Error).message}`;
return new ServiceResponse(ResponseStatus.Failed, errorMessage, null, StatusCodes.INTERNAL_SERVER_ERROR);
const errorMessage = `Error fetching content ${(error as Error).message}`;
const serviceResponse = new ServiceResponse(
ResponseStatus.Failed,
errorMessage,
null,
StatusCodes.INTERNAL_SERVER_ERROR
);

handleServiceResponse(serviceResponse, res);
return;
}
});

Expand Down