Skip to content

Use axios for fetching challenges #12

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

Merged
merged 1 commit into from
Jul 10, 2025
Merged

Conversation

vas3a
Copy link
Collaborator

@vas3a vas3a commented Jul 10, 2025

No description provided.

@@ -50,66 +50,66 @@ export class QueryChallengesTool {
accessToken,
);

if (!challenges.ok) {
if (challenges.status < 200 || challenges.status >= 300) {

Choose a reason for hiding this comment

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

low
readability
The condition challenges.status < 200 || challenges.status >= 300 is technically correct for checking non-success HTTP status codes, but consider using !challenges.status.toString().startsWith('2') for improved readability and to clearly convey the intent of checking for non-2xx status codes.

this.logger.error(
`Failed to fetch challenges from Topcoder API: ${challenges.statusText}`,
);
try {
this.logger.error(await challenges.json());
this.logger.error(challenges.data);

Choose a reason for hiding this comment

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

medium
correctness
The change from await challenges.json() to challenges.data assumes that challenges.data is always available and correctly formatted. Ensure that challenges.data is reliably structured as expected, or add error handling for cases where it might not be.

page: Number(challenges.headers.get('x-page')) || 1,
type: 'text',
text: JSON.stringify({
page: Number(challenges.headers['x-page']) || 1,

Choose a reason for hiding this comment

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

medium
correctness
Consider checking if challenges.headers['x-page'] is a valid number before using Number() to avoid potential NaN values.

Number(challenges.headers.get('x-per-page')) ||
challengesData.length ||
Number(challenges.headers['x-per-page']) ||
(Array.isArray(challengesData) ? challengesData.length : 0) ||

Choose a reason for hiding this comment

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

medium
correctness
Ensure challenges.headers['x-per-page'] is a valid number before conversion to prevent NaN results, which could affect pagination logic.

0,
total:
Number(challenges.headers.get('x-total')) ||
challengesData.length ||
Number(challenges.headers['x-total']) ||

Choose a reason for hiding this comment

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

medium
correctness
Validate challenges.headers['x-total'] to ensure it is a number before conversion to avoid potential NaN issues.

0,
nextPage: challenges.headers.get('x-next-page')
? Number(challenges.headers.get('x-next-page'))
nextPage: challenges.headers['x-next-page']

Choose a reason for hiding this comment

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

medium
correctness
Consider checking if challenges.headers['x-next-page'] is a valid number before using Number() to avoid potential NaN values.

headers,
});
const response = await axios.get(stringUrl, { headers });
return response;

Choose a reason for hiding this comment

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

medium
design
Consider returning response.data instead of the entire response object. Axios responses include metadata that may not be necessary for the caller, and returning only the data improves encapsulation and clarity of the service's API.

@vas3a vas3a merged commit 3a68cfd into dev Jul 10, 2025
1 check passed
@vas3a vas3a deleted the logger-level-for-challenges branch July 10, 2025 16:28
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.

1 participant