Mitja Nikolaus | e920808 | 2018-07-30 14:22:09 +0200 | [diff] [blame] | 1 | """Response descriptions for HTTP responses.""" |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 2 | from typing import Tuple, Type |
| 3 | |
| 4 | from rest_framework.exceptions import APIException |
Mitja Nikolaus | e920808 | 2018-07-30 14:22:09 +0200 | [diff] [blame] | 5 | |
| 6 | |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 7 | def default_desc(exception: Type[APIException]) -> Tuple[int, str]: |
Mitja Nikolaus | e920808 | 2018-07-30 14:22:09 +0200 | [diff] [blame] | 8 | """Get the default response description for an exception. |
| 9 | |
| 10 | Args: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 11 | exception: |
Mitja Nikolaus | e920808 | 2018-07-30 14:22:09 +0200 | [diff] [blame] | 12 | A subclass of APIException for which the response description |
| 13 | should be returned. |
| 14 | |
| 15 | Returns: |
Mitja Nikolaus | 9c3b29e | 2018-08-22 11:17:50 +0200 | [diff] [blame] | 16 | A tuple containing the matching status code and default description |
| 17 | for the exception. |
Mitja Nikolaus | e920808 | 2018-07-30 14:22:09 +0200 | [diff] [blame] | 18 | |
| 19 | """ |
| 20 | return exception.status_code, str(exception.default_detail) |