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

feat: improve validations and errors for shortUrl and longUrl #2100

Merged
merged 2 commits into from
Dec 6, 2022

Conversation

halfwhole
Copy link
Collaborator

@halfwhole halfwhole commented Nov 28, 2022

Problem

The server errors for invalid short and long URLs are not always caught up-front at the Joi validator level, leaving them to be caught at the Sequelize level or via safe browsing checks (which is not that great). Plus, the error messages thrown are not very informative or well-formatted.

Closes this Notion issue

Solution

  • Shift Joi validator checks for URLs before safe browsing checks (in urlCheckController) and various file checks (in fileCheckController)
  • Add long URL Joi validations for invalid URLs and circular redirect checks
  • Update error messages to be more informative
  • Standardise error messages, including between Joi validations and Sequelize models - e.g. all end with period, capitalize "URL", "not allowed" vs. "prohibited", etc.

There's a bit of error duplication across the Joi schemas and Seqeulize validations, but I can't think of an easy fix - it seems ok for now, so will leave it as it is

Tests

  • (Eventually) Add integration tests for invalid short and long URL formats

@halfwhole
Copy link
Collaborator Author

Update: checked with Clement on the new error messages in this PR, got a LGTM

Copy link
Contributor

@thanhdatle thanhdatle left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for working on this!

Copy link
Contributor

@gweiying gweiying left a comment

Choose a reason for hiding this comment

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

lgtm!

@gweiying gweiying merged commit 8a90643 into develop Dec 6, 2022
@gweiying gweiying deleted the feat/improve-url-validations branch December 6, 2022 01:31
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.

3 participants