twilio/flask-restful — pull request #126 by dougblack (2013-09-16 22:16:50+00:00)
Title: allow overriding default response for failed auth

Fixes #83.

When `abort(401)` is called it constructs the response by calling `utils.unauthorized`. This pull moves `unauthorized` onto the `Api` object so it can be overridden.

#### Example Usage

Subclass `restful.Api`:

```python
class Api(restful.Api):
def unauthorized(response):
data = {'error': 'Authorization failed'}
return make_response(data)
```

Or manually set it:

```python
def custom_unauthorized(response):
data = {"error": "Authorization failed"}
return make_response(data)

app = Flask(__name__)
api = restful.Api(app)
api.unauthorized = custom_unauthorized
```