DEV Community

Discussion on: Flask Rest API -Part:4- Exception Handling

Collapse
 
argiriraj profile image
Giriraj AR

Hi Paurakh,

How to import in case of 2 different error modules, for example
resource_errors and user_errors?

I tried as below but its not working

from resources.errors import resource_errors
from user.errors import user_errors
api = Api(app, errors={'user_errors':user_errors, 'resource_errors':resource_errors})

Will be great if you can suggest me what i am doing wrong?

Collapse
 
argiriraj profile image
Giriraj AR

I Found a solution,

the parameter error accepts only dictionary, so merge the different error dictionary into one and then pass that dictionary
example:
collective_errors = {**user_errors, **resource_errors}
api = Api(app, errors=collective_errors)