Commit da283881 authored by Stavros-Anastasios Charismiadis's avatar Stavros-Anastasios Charismiadis
Browse files

improve error function responses

parent 35846b01
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ class ProviderManagementOperations(Resource):
            api_provider_enrolment_details = clean_empty(api_provider_enrolment_details)

            result = mycol.find_one_and_update(result, {"$set":api_provider_enrolment_details}, projection={'_id': 0},return_document=ReturnDocument.AFTER ,upsert=False)

            result = clean_empty(result)

            current_app.logger.debug("Provider domain updated in database")
+26 −14
Original line number Diff line number Diff line
from ..models.problem_details import ProblemDetails
from ..encoder import JSONEncoder
from ..util import dict_to_camel_case
from flask import Response
from ..util import dict_to_camel_case, clean_empty
from flask import Response, current_app
import json

mimetype = "application/json"
@@ -14,28 +14,40 @@ def make_response(object, status):


def internal_server_error(detail, cause):
    prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Internal Server Error", status=500, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
    # BEFORE: prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause)
    # prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Internal Server Error", status=500, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
    prob = ProblemDetails(title="Internal Server Error", status=500, detail=detail, cause=cause)

    return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=500, mimetype=mimetype)
    prob = prob.to_dict()
    prob = clean_empty(prob)

    return Response(json.dumps(dict_to_camel_case(prob), cls=JSONEncoder), status=500, mimetype=mimetype)


def forbidden_error(detail, cause):
    prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Forbidden", status=403, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
    # BEFORE: prob = ProblemDetails(title="Forbidden", status=403, detail=detail, cause=cause)
    prob = ProblemDetails(title="Forbidden", status=403, detail=detail, cause=cause)

    prob = prob.to_dict()
    prob = clean_empty(prob)

    return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=403, mimetype=mimetype)
    # return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=403, mimetype=mimetype)
    return Response(json.dumps(dict_to_camel_case(prob), cls=JSONEncoder), status=403, mimetype=mimetype)


def bad_request_error(detail, cause, invalid_params):
    prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Bad Request", status=400, detail=detail, cause=cause, invalid_params=invalid_params, supported_features="fffff")
    # BEFORE: prob = ProblemDetails(title="Bad Request", status=400, detail=detail, cause=cause, invalid_params=invalid_params)
    # prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Bad Request", status=400, detail=detail, cause=cause, invalid_params=invalid_params, supported_features="fffff")
    prob = ProblemDetails(title="Bad Request", status=400, detail=detail, cause=cause, invalid_params=invalid_params)

    return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=400, mimetype=cause)
    prob = prob.to_dict()
    prob = clean_empty(prob)

    return Response(json.dumps(dict_to_camel_case(prob), cls=JSONEncoder), status=400, mimetype=cause)


def not_found_error(detail, cause):
    prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Not Found", status=404, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
    # BEFORE: prob = ProblemDetails(title="Not Found", status=404, detail=detail, cause=cause)
    # prob = ProblemDetails(type="http://www.ietf.org/rfc/rfc2396.txt", instance="http://www.ietf.org/rfc/rfc2396.txt", title="Not Found", status=404, detail=detail, cause=cause, invalid_params=[{"param":"","reason":""}], supported_features="fffff")
    prob = ProblemDetails(title="Not Found", status=404, detail=detail, cause=cause)

    prob = prob.to_dict()
    prob = clean_empty(prob)

    return Response(json.dumps(dict_to_camel_case(prob.to_dict()), cls=JSONEncoder), status=404, mimetype=mimetype)
 No newline at end of file
    return Response(json.dumps(dict_to_camel_case(prob), cls=JSONEncoder), status=404, mimetype=mimetype)
 No newline at end of file