Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flask autherror

from flask import Flask, abort
from auth import AuthError
# depending on the error either 400 or any
#just work with the following

@app.errorhandler(404)
def resource_not_found(error):
  return jsonify({
    "success":  True,
    "error": 404,
    "message": "Resource not found"
  }), 404
##This works for any type of status code error
#You'll follow the same steps just change the error value and message :)

### also for Auth error. 

@app.errorhandler(AuthError)
def AuthError(error):
  """Need to return JSON and we'll have to get a response""" 
  response = jsonify(error)
  response.status_code = error.status_code
  
  return response
Comment

PREVIOUS NEXT
Code Example
Python :: python time library 
Python :: .text python 
Python :: python append to 2d array 
Python :: python operators 
Python :: print pattern a shape in python 
Python :: matplotlib measure the width of text 
Python :: max float python 
Python :: Export a Pandas dataframe as a table image 
Python :: pvm python 
Python :: dataframe to dictionary 
Python :: check pyenv version windows 
Python :: how to rename rengeindex pandas 
Python :: python add to file 
Python :: chr() python 
Python :: python reverse 2d list 
Python :: django admin.py all fields 
Python :: flask quickstart 
Python :: django never_cache example 
Python :: python parcourir un dictionnaire 
Python :: drop rows from dataframe based on column value 
Python :: pandas sep 
Python :: python find in list 
Python :: call a function onclick tkinter 
Python :: the list of prime number in a given range python 
Python :: clone website in python 
Python :: django dockerfile multistage 
Python :: empty dictionary python 
Python :: move items from one list to another python 
Python :: django login view 
Python :: How to store password in hashlib in python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =