hardware.all()
to api.model()
would treat it as one big array rather than and array of sqlalchmey results,
@api.errorhandler
associates an exception of your choice with a message and http message to send back via a func. so@api.errorhandler(BusinessError)
def handle_business_error(error):
return {"message": "A logical error has occurred"}, 418
@api.errorhandler(AnotherBusiness):
def hand_another_business_error(error):
return {"message": "a different business logic error"}, 451
provide api.errorhandler
with the error you want need it to catch
db_scenario.to_domain()
will raise, but just setup handlers for each one of those. You can see in my example, I'm just calling raise
without an try/except code and it's caught, a 418 is returned, along with the message i passed it
db
errors, and they all derive from a single err class MyDbError(Exception):
pass
class BadQuery(MyDbError):
pass
class BadFormatting(MyDbError):
pass
api.errorhandler(MyDbError)
and catch everything that has inherited MyDbError
what's it actually returning? What's the 500 and the stacktrace in the log?
I sent some screen , I reproduced your pastebin to catch an exception https://prnt.sc/123j36f and handle it with my function https://prnt.sc/123j4lg but when I test the request I have HttpError 500 instead of 418
what are the app logs saying in conjunction with the 500? Are the app logs quiet and it's just returning 500, or is the application throwing a stacktrace?
https://prnt.sc/1258amm
Here is the stacktrace
hello @j5awry
I successed to make the simple example on your pastebin working.
I tried to implement it on a very simple get routes but It didnt work , https://pastebin.ubuntu.com/p/8NWdRCgz38/
I made to many tests and it always return http error 500.
I'll continue my research
flasgger
is doing could be an interesting entry point. but it's going to take code change in flask-restx
@Gidgidonihah : Reading the code, the intent is that errorhandlers get checked for the restx.API and it's children (restx.API.namespace). It wouldn't make sense, to me, for the framework to go up the chain as well.
So self + children
vs. self + parents + children
. self + children
makes sense to me for checking handlers. But I may be misinterpreting the question?
@Abdur-rahmaanJ If you don't mind me asking, is this an on-prem or cloud hosted? And is it possible to add authentication at other layers? It depends a lot on your setup, but something like using JWT with NGinx, or x509 based auth at Apache Webserver are other possibilities. But there's a lot of nuance there. I do think we need to figure out a better way of handling the pre-generated doc endpoint, and I think what
flasgger
is doing could be an interesting entry point. but it's going to take code change inflask-restx
Cloud-hosted, server-based auth is a great option also but see the above