""" Code Errors reference: - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status - https://developer.mozilla.org/es/docs/Web/HTTP/Status """ import json from flask import ( Response ) def internal_server_error(e): response = Response( response=json.dumps({ "msg": "Something went wrong", "_desc": str(e) }), status=500, mimetype="applications/json" ) return response def schema_validation_error(e): response = Response( response=json.dumps({ "msg": "Request is missing required fields", "_desc": str(e) }), status=400, mimetype="applications/json" ) return response def unauthorized_error(e): response = Response( response=json.dumps({ "msg": "Invalid username or password", "_desc": str(e) }), status=401, mimetype="applications/json" ) return response def disable_register_error(e): response = Response( response=json.dumps({ "msg": "Unauthorized create user", "_desc": str(e) }), status=401, mimetype="applications/json" ) return response def error_method(): response = Response( response=json.dumps({ "msg": "Method unauthorized for your user" }), status=401, mimetype="applications/json" ) return response # Status 204 does not show any msg def not_data_found(): response = Response( status=204, mimetype="applications/json" ) return response # ##### # Heroe # ##### def heroe_already_exists_error(e): response = Response( response=json.dumps({ "msg": "Heroe with given full-name already exists", "_desc": str(e) }), status=400, mimetype="applications/json" ) return response def updating_heroe_error(e): response = Response( response=json.dumps({ "msg": "Updating heroe added by other is forbidden", "_desc": str(e) }), status=403, mimetype="applications/json" ) return response def deleting_heroe_error(e): response = Response( response=json.dumps({ "msg": "Deleting heroe added by other is forbidden", "_desc": str(e) }), status=403, mimetype="applications/json" ) return response # ##### # User # ##### def user_already_exists_error(e): response = Response( response=json.dumps({ "msg": "User with given username or email already exists", "_desc": str(e) }), status=400, mimetype="applications/json" ) return response def updating_user_error(e): response = Response( response=json.dumps({ "msg": "Updating user added by other is forbidden", "_desc": str(e) }), status=403, mimetype="applications/json" ) return response def deleting_user_error(e): response = Response( response=json.dumps({ "msg": "Deleting user added by other is forbidden", "_desc": str(e) }), status=403, mimetype="applications/json" ) return response