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

Already shortened url message fixed #38

Merged
merged 4 commits into from
Jun 22, 2019
Merged

Already shortened url message fixed #38

merged 4 commits into from
Jun 22, 2019

Conversation

hamidaskarov
Copy link
Contributor

I think it(#37 ) happens because of some errors return a list instead of string, so i convert this list to string if it is list.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 68.09% when pulling f58b6de on whoami38:already_shortened_url into 91572f9 on amitt001:master.

Repository owner deleted a comment from coveralls Jun 17, 2019
err = {}
err["error"] = (" ".join(API_ERROR(e.args[0])['error'])
if isinstance(API_ERROR(e.args[0])['error'],list)
else API_ERROR(e.args[0])['error'])
Copy link
Owner

Choose a reason for hiding this comment

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

Good find. This PR will fix the issue but I reckon this same issue might occur for some other endpoints also and that would require us to copy this code there. I think we should fix the source of the problem. This https://github.com/amitt001/pygmy/blob/master/pygmy/rest/shorturl.py#L44 is returning a dict {'error': ['URL is already a pygmy shortened link.'], 'long_url': ['URL is already a pygmy shortened link.']} with a list as the value. This should be a string. Would you mind updating the PR to fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed code, and convert error message to string in API part. But a question came to my mind, isn't it possible to have multiple error in the same time? If it possible, is converting to string good idea?

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks!
yes, it's possible to have multiple errors at the same time but not with how this webapp works. All form validation is already done on the Django app side and this is the only check that's performed in the backed.
But you are right that it may not be the best idea to join all errors if API is used independently of the webapp. One way, I think, this issue can be solved is by keep on passing error list and on webapp side(frontend or Django app) format it in the form that it shows all the errors properly.
Frontend already supports this for form validation

Screenshot 2019-06-21 at 14 50 22

@hamidaskarov
Copy link
Contributor Author

Instead of joining API errors, i have changed the error_msg.py file which getting errors from API and convert dict for rendering, it now return fully lists instead of list&string mix and because of that i also changed some(400.html,404.html,500.html) templates.Instead of printing error directly i've added for loops for printing elements of list.

@@ -44,7 +44,7 @@ def post(self):
if errors:
log.error('Error in the request payload %s', errors)
if errors.get('long_url'):
errors.update({'error': errors.get('long_url')})
errors.update({'error': " ".join(errors.get('long_url'))})
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can get rid of this. This is not required anymore after changes to the template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Sorry, i forgot to remove join.

@amitt001 amitt001 merged commit d15f631 into amitt001:master Jun 22, 2019
@amitt001
Copy link
Owner

Good job! Thanks for the PR :)

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.

None yet

3 participants