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

refactor: change return error.respond() to raise #6780

Merged
merged 48 commits into from
May 6, 2020

Conversation

Rits1272
Copy link
Member

Fixes #6665

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

@codecov
Copy link

codecov bot commented Jan 23, 2020

Codecov Report

Merging #6780 into development will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           development    #6780   +/-   ##
============================================
  Coverage        66.38%   66.38%           
============================================
  Files              313      313           
  Lines            15360    15360           
============================================
  Hits             10197    10197           
  Misses            5163     5163           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab008c5...ab008c5. Read the comment docs.

app/instance.py Outdated
}),
429,
Copy link
Member

Choose a reason for hiding this comment

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

Why are you changing this?

app/instance.py Outdated
@@ -269,5 +270,17 @@ def ratelimit_handler(error):
})


@app.errorhandler(HTTPException)
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to handle any HTTPException, we want to handle our custom exceptions

app/instance.py Outdated
@@ -6,6 +6,7 @@

import sys
from flask import Flask, json, make_response
from werkzeug.exceptions import HTTPException

Choose a reason for hiding this comment

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

'werkzeug.exceptions.HTTPException' imported but unused

@Rits1272
Copy link
Member Author

Is that what we want @iamareebjamal?

app/instance.py Outdated
403,
{
'Content-Type': 'application/vnd.api+json'
})
Copy link
Member

Choose a reason for hiding this comment

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

Still wrong

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you kindly please tell me @iamareebjamal what changes I need to do? I am registering error handler just as I did before for 429.

Copy link
Member

Choose a reason for hiding this comment

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

You can read the issue again

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay

@Rits1272
Copy link
Member Author

Rits1272 commented Feb 9, 2020

Please review my changes @iamareebjamal

@iamareebjamal
Copy link
Member

It's still wrong. Read the issue again

@Rits1272
Copy link
Member Author

Rits1272 commented Feb 9, 2020

Please again check @iamareebjamal. Sorry for bothering you

@iamareebjamal
Copy link
Member

Still wrong

@iamareebjamal
Copy link
Member

Still wrong. Read my 2 comments carefully

@Rits1272
Copy link
Member Author

Please check this @iamareebjamal !



class UnprocessableEntity(JsonApiException):
class UnprocessableEntity(JsonApiException, ErrorResponse):
Copy link
Member

Choose a reason for hiding this comment

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

Remove ErrorResponse

@Rits1272
Copy link
Member Author

Please review again @iamareebjamal

@Rits1272
Copy link
Member Author

Rits1272 commented Mar 2, 2020

Kindly please check @iamareebjamal

@@ -10,7 +11,7 @@ class UnprocessableEntity(JsonApiException):
status = 422


class ConflictException(JsonApiException):
class ConflictException(JsonApiException, ErrorResponse):
Copy link
Member

Choose a reason for hiding this comment

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

Remove ErrorResponse

@Rits1272
Copy link
Member Author

Rits1272 commented Mar 6, 2020

I have made the required changes @iamareebjamal

@@ -1,4 +1,5 @@
from flask_rest_jsonapi.exceptions import JsonApiException
from app.api.helpers.errors import ErrorResponse

Choose a reason for hiding this comment

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

'app.api.helpers.errors.ErrorResponse' imported but unused

return ForbiddenError(
{'source': ''}, 'Super admin access is required'
).respond()
raise ForbiddenError({'source': ''}, 'Super admin access is required')

Choose a reason for hiding this comment

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

Black would make changes.

@@ -27,15 +27,15 @@ def is_super_admin(view, view_args, view_kwargs, *args, **kwargs):
"""
user = current_user
if not user.is_super_admin:
return ForbiddenError({'source': ''}, 'Super admin access is required').respond()
raise ForbiddenError({'source': ''}, 'Super admin access is required')

Choose a reason for hiding this comment

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

Black would make changes.

@niranjan94
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 2
           

Clones removed
==============
+ app/api/event_invoices.py  -1
+ app/api/helpers/permission_manager.py  -2
+ app/api/orders.py  -1
+ app/api/role_invites.py  -2
         

See the complete overview on Codacy

@iamareebjamal
Copy link
Member

Finally, after 48 commits for a small change

@iamareebjamal iamareebjamal changed the title refactor: Registered error handlers and changed return statements to raise refactor: change return error.respond() to raise May 6, 2020
@iamareebjamal iamareebjamal merged commit cea6494 into fossasia:development May 6, 2020
@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 6, 2020

This pull request fixes 6 alerts when merging ab008c5 into 40a1f28 - view on LGTM.com

fixed alerts:

  • 6 for Illegal raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Register error handler for custom errors and change return statements to raise
4 participants