-
Notifications
You must be signed in to change notification settings - Fork 70
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 max attempt on URL generation #51
base: main
Are you sure you want to change the base?
Conversation
onepixel.production.env
Outdated
MAIN_SITE_HOST=1px.li | ||
URL_GEN_MAX_RETRIES=1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
production retries should not be 1000 either, 10 is a better limit
commenting below, why the error message is not good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to 10
src/controllers/urls.go
Outdated
@@ -53,6 +54,10 @@ var ( | |||
status: fiber.ErrForbidden.Code, | |||
message: "this shortURL is not allowed to be created", | |||
} | |||
MaxRetriesReachedError = &UrlError{ | |||
status: fiber.ErrInternalServerError.Code, | |||
message: "max number of attempts to generate a URL reached. Please try after some time", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is not a good error to give the client, because the client is technically not "retrying" these many times. It is our code's internal recursion causing it.
A 508 StatusLoopDetected
error with message "server exhausted attempts to generate a unique shortUrl, please try again" would be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. Have updated the message.
Adds a limit on the maximum number of retries in case of collisions.
Closes Issue #50