DEV Community

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

Collapse
 
atlasloewenherz profile image
atlasloewenherz • Edited

very good article! thanks

please update the above link, you current references a 404 this is the new link:

flask-restful.readthedocs.io/en/la...

a minor addition:

in the new docs its says:

"Note: Custom Exceptions must have HTTPException as the base Exception."

if i do change the errors in the dictionary to extends HTTPException instead of Exception i get:

   ~  curl -v -X POST --header 'Content-Type: application/json' -d '{"password":"Password20", "email":"user212@mail.com", "phone":"016553225644"}' 'http://127.0.0.1:8888/user/register'                                                               ✔  22:30:26 
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8888...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8888 (#0)
> POST /user/register HTTP/1.1
> Host: 127.0.0.1:8888
> User-Agent: curl/7.65.3
> Accept: */*
> Content-Type: application/json
> Content-Length: 80
>
* upload completely sent off: 80 out of 80 bytes
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html
< Content-Length: 121
< Server: Werkzeug/0.16.0 Python/3.7.6
< Date: Mon, 23 Mar 2020 21:30:28 GMT
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>None Unknown Error</title>
<h1>Unknown Error</h1>
<p></p>
* Closing connection 0

otherwise its an http 500 error and the flask debugging views ( html)

Thanks