Returns a smart 404 page that contains documentation for the written API
(self, base_url=None)
| 315 | return next(iter(request_version or (None,))) |
| 316 | |
| 317 | def documentation_404(self, base_url=None): |
| 318 | """Returns a smart 404 page that contains documentation for the written API""" |
| 319 | base_url = self.base_url if base_url is None else base_url |
| 320 | |
| 321 | def handle_404(request, response, *args, **kwargs): |
| 322 | url_prefix = request.forwarded_uri[:-1] |
| 323 | if request.path and request.path != "/": |
| 324 | url_prefix = request.forwarded_uri.split(request.path)[0] |
| 325 | |
| 326 | to_return = OrderedDict() |
| 327 | to_return["404"] = ( |
| 328 | "The API call you tried to make was not defined. " |
| 329 | "Here's a definition of the API to help you get going :)" |
| 330 | ) |
| 331 | to_return["documentation"] = self.documentation( |
| 332 | base_url, self.determine_version(request, False), prefix=url_prefix |
| 333 | ) |
| 334 | |
| 335 | if self.output_format == hug.output_format.json: |
| 336 | response.data = hug.output_format.json(to_return, indent=4, separators=(",", ": ")) |
| 337 | response.content_type = "application/json; charset=utf-8" |
| 338 | else: |
| 339 | response.data = self.output_format(to_return, request=request, response=response) |
| 340 | response.content_type = self.output_format.content_type |
| 341 | |
| 342 | response.status = falcon.HTTP_NOT_FOUND |
| 343 | |
| 344 | handle_404.interface = True |
| 345 | return handle_404 |
| 346 | |
| 347 | def version_router( |
| 348 | self, request, response, api_version=None, versions=None, not_found=None, **kwargs |
no outgoing calls