SkygearIO / py-skygear

Skygear Cloud Code Python SDK
https://skygear.io
Other
8 stars 20 forks source link

Provide a way to override lambda's errorous http status code #179

Open limouren opened 6 years ago

limouren commented 6 years ago

Currently in py-skygear, SkygearException allows us to cusomize an error response:

    raise SkygearException(
        code=9999,
        message='Something has gone wrong. Handle it in client side.',
        info={},
    )

It would produce a http response like this:

HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Length: 142
Content-Type: application/json
Date: Wed, 31 Jan 2018 14:14:35 GMT
Server: Skygear Server/1.2.0-31-g68cb380

{
    "error": {
        "code": 9999, 
        "message": "You have done something wrong. Handle it in client side.", 
        "name": "ErrorCode(9999)"
    }
}

Note that skygear always returns a 500, while such errors are typically a 4xx. It would be great if skygear could provide a way for dev to decide a different http status code to provide better semantics for their API.

Expected Results

Actual Results

Steps to reproduce

1. 2. 3.