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

Add Custom Errors #85

Merged
merged 12 commits into from
Nov 27, 2023
Merged

Add Custom Errors #85

merged 12 commits into from
Nov 27, 2023

Conversation

seditionist
Copy link
Contributor

closes #84

  • add InvalidFormatError, InvalidRSNError, PlayerNotFoundError, and HiScoresError
  • update getStats to handle errors from Axios

src/utils/constants.ts Outdated Show resolved Hide resolved
src/hiscores.ts Outdated Show resolved Hide resolved
src/hiscores.ts Outdated Show resolved Hide resolved
Copy link
Owner

@maxswa maxswa left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to review this! I think this is a good change overall, just needs some tweaks. Thank you for the PR!

src/hiscores.ts Outdated Show resolved Hide resolved
src/hiscores.ts Outdated Show resolved Hide resolved
@maxswa
Copy link
Owner

maxswa commented Nov 26, 2023

When resolving the conflict, feel free to just accept all of your changes, it came from updating the axios version but isn't necessary anymore since you removed the use of AxiosResponse anyway.

src/hiscores.ts Outdated
): Promise<HiscoresResponse | undefined> =>
otherGamemodes.includes(mode)
? getOfficialStats(rsn, mode, options?.axiosConfigs?.[mode])
.catch(err => err)
Copy link
Owner

Choose a reason for hiding this comment

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

Similarly to the comment for the emptyResponse, we need to return undefined in the case of a caught error. Otherwise the conditions of the if statements below will be true when the error object is present as the response.

We should probably log the error in some way, or maybe even consider returning the errors in some format. But on the other hand I'm also hesitant to modify the structure of the Player object. 🤔 Not entirely sure what to do here, but since we're updating errors in the PR, it seems like a good opportunity to improve error handling in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I wonder what the expected behavior would be for the case where the initial stat lookup succeeds, but there is a 500 status code during the subsequent lookups. We could add an optional strict parameter that throws if any of the lookups error.

I will check what the previous behavior would have been prior to the JSON endpoint update. Realistically, the only error that would occur is HiScoresError, unless the account in question name changes or gets banned in-between the first lookup and one of the gamemode lookups.

Copy link
Owner

Choose a reason for hiding this comment

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

I like the idea of a strict mode! I think that if getStats is used for a main account, it will 404 when looking up ironman stats. So we'd probably want to restrict it to only throwing/reporting on HiScoresErrors. But I think it's fair to wait for a future enhancement to implement this so we don't delay this great change any longer!

@maxswa
Copy link
Owner

maxswa commented Nov 27, 2023

Thank you for this change and the quick modifications despite my lengthy delays! 😅 This is a nice improvement and will hopefully alleviate your rate-limiting issue. I will be publishing this shortly.

@maxswa maxswa merged commit 55312ba into maxswa:main Nov 27, 2023
1 check passed
@seditionist
Copy link
Contributor Author

Happy to contribute to something that I have been using for so long. Thanks for the insightful feedback on the changes! Looking forward to the next opportunity to work with you on this.

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.

PLAYER_NOT_FOUND_ERROR
2 participants