Skip to content

Conversation

billsedison
Copy link
Collaborator

@billsedison billsedison requested a review from jmgasper September 6, 2025 02:02
typeof challengeId !== 'string' ||
challengeId.trim() === ''
) {
throw new Error('Invalid challengeId parameter');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more specific exception class like BadRequestException instead of throwing a generic Error for invalid challengeId to provide more context and consistency with other error handling.

error,
);

if (error.message === 'Invalid challengeId parameter') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling here could be improved by using specific exception classes instead of re-throwing a generic Error. For example, use BadRequestException or NotFoundException directly when catching specific errors.


// Handle Resource API errors based on HTTP status codes
if (error.message === 'Cannot get data from Resource API.') {
const statusCode = (error as Error & { statusCode?: number })
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if statusCode is undefined before comparing it to avoid potential runtime errors if statusCode is not present in the error object.

}
}

if (error.message && error.message.includes('not found')) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message check error.message.includes('not found') might be too broad and could potentially catch unintended errors. Consider refining the condition or using a more specific error handling mechanism.

description: 'Total number of reviewers for the challenge',
example: 2,
})
@IsNumber()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a validation decorator such as @IsInt() to ensure that totalReviewers is an integer, as fractional reviewers do not make sense.

description: 'Total number of submissions for the challenge',
example: 4,
})
@IsNumber()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a validation decorator such as @IsInt() to ensure that totalSubmissions is an integer, as fractional submissions do not make sense.

description: 'Total number of submitted reviews',
example: 6,
})
@IsNumber()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a validation decorator such as @IsInt() to ensure that totalSubmittedReviews is an integer, as fractional reviews do not make sense.

example: 75.0,
})
@IsNumber()
progressPercentage: number;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a validation decorator such as @IsPositive() to ensure that progressPercentage is a positive number, as negative progress does not make sense.

@@ -79,7 +79,10 @@ export class ResourceApiService {
} catch (e) {
if (e instanceof AxiosError) {
this.logger.error(`Http Error: ${e.message}`, e.response?.data);
throw new Error('Cannot get data from Resource API.');
const error = new Error('Cannot get data from Resource API.');
(error as any).statusCode = e.response?.status;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more specific type instead of any for the error object to improve type safety and maintainability.

throw new Error('Cannot get data from Resource API.');
const error = new Error('Cannot get data from Resource API.');
(error as any).statusCode = e.response?.status;
(error as any).originalMessage = e.response?.data?.message;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more specific type instead of any for the error object to improve type safety and maintainability.

@jmgasper jmgasper merged commit 55d46e8 into develop Sep 6, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants