def my_example(event, context):
    try:
        response = example_service(event)
    except HttpBaseException as e:
        return e.get_response()

    return HttpResponse.success(response)
Exemplo n.º 2
0
 def __init__(self, status_code, body=None):
     super().__init__(HttpResponse.build(status_code), body)
Exemplo n.º 3
0
 def __init__(self, body=None):
     super().__init__(HttpResponse.error(), body)
Exemplo n.º 4
0
 def __init__(self, body=None):
     super().__init__(HttpResponse.unprocessable(), body)
Exemplo n.º 5
0
 def __init__(self, body=None):
     super().__init__(HttpResponse.forbidden(), body)
Exemplo n.º 6
0
 def __init__(self, body=None):
     super().__init__(HttpResponse.unauthorized(), body)
Exemplo n.º 7
0
 def __init__(self, body=None):
     super().__init__(HttpResponse.bad_request(), body)
Exemplo n.º 8
0
 def __init__(self, body=None):
     super().__init__(HttpResponse.not_found(), body)
Exemplo n.º 9
0
def test_get_response():
    response = exceptions.HttpBaseException(
        HttpResponse.success()).get_response()
    assert response == {'statusCode': 200, 'body': None}
Exemplo n.º 10
0
def test_get_response_error():
    response = exceptions.HttpBaseException(
        HttpResponse.error()).get_response()
    assert response.get('statusCode') == 500
Exemplo n.º 11
0
def test_get_response_unauthorized():
    response = exceptions.HttpBaseException(
        HttpResponse.unauthorized()).get_response()
    assert response.get('statusCode') == 401
Exemplo n.º 12
0
def test_get_response_bad_request():
    response = exceptions.HttpBaseException(
        HttpResponse.bad_request()).get_response()
    assert response.get('statusCode') == 400
Exemplo n.º 13
0
def test_get_response_with_body():
    response = exceptions.HttpBaseException(HttpResponse.success(),
                                            body={
                                                'message': 'ok'
                                            }).get_response()
    assert response == {'statusCode': 200, 'body': '{"message": "ok"}'}