Skip to content

Commit

Permalink
✨ Error 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
perdy committed Jan 19, 2023
1 parent 1d40ce8 commit f384ef6
Show file tree
Hide file tree
Showing 15 changed files with 2,017 additions and 2,117 deletions.
26 changes: 22 additions & 4 deletions examples/error.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import uvicorn

from flama import Flama, Router
import flama

app = Flama(
app = flama.Flama(
title="Hello-🔥",
version="1.0",
description="My first API",
Expand All @@ -28,15 +28,15 @@ def home():
return {"message": "Hello 🔥"}


error_app = Router()
error_app = flama.Router()


class FooException(Exception):
...


@error_app.route("/500")
def error_500(param: int):
def error_500():
"""
tags:
- Error
Expand All @@ -53,6 +53,24 @@ def error_500(param: int):

app.mount("/error", app=error_app)

# Mount a complex urls tree to illustrate in 404 error page
bar_app = flama.Router()


@bar_app.route("/foobar/")
def foobar():
...


@bar_app.route("/barfoo/")
def barfoo():
...


foo_app = flama.Router()
foo_app.mount("/bar/", bar_app)

app.mount("/foo/", foo_app)

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
4 changes: 2 additions & 2 deletions flama/debug/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def build(cls, request: "http.Request", exc: Exception) -> "ErrorContext":
class NotFoundContext:
request: Request
environment: Environment
urls: App
app: App

@classmethod
def build(cls, request: "http.Request", app: "Flama") -> "NotFoundContext":
return cls(request=Request.from_request(request), environment=Environment.from_system(), urls=App.from_app(app))
return cls(request=Request.from_request(request), environment=Environment.from_system(), app=App.from_app(app))
Loading

0 comments on commit f384ef6

Please sign in to comment.