Import from agentic-semantic-web/ into restructured repo: - 7 packs (apache, caddy, flask, hugo, nginx, pandoc, python) - shared error pages (403-503) - 17 lab experiments (boilerplate, charts, misc) - 31 example pages (charts, components, content, layout, vault) - 2 themes (garden, trentuna stub) - 4 docs (llms.txt, vocabulary, philosophy, agent-directive) - lineage.md (Pico/Open Props/Charts.css history) - Hugo mounts for lab/ and examples/ All agentic.css references updated to asw.css. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
82 lines
1.9 KiB
Markdown
82 lines
1.9 KiB
Markdown
# ASW Flask/FastAPI Error Pack
|
|
|
|
Drop-in styled error responses for Flask and FastAPI applications.
|
|
|
|
## Usage
|
|
|
|
```python
|
|
# Copy asw_errors.py to your project directory, then:
|
|
|
|
from flask import Flask
|
|
from asw_errors import register_asw_errors
|
|
|
|
app = Flask(__name__)
|
|
register_asw_errors(app)
|
|
```
|
|
|
|
```python
|
|
from fastapi import FastAPI
|
|
from asw_errors import register_asw_errors
|
|
|
|
app = FastAPI()
|
|
register_asw_errors(app)
|
|
```
|
|
|
|
## What you get
|
|
|
|
ASW-styled HTML error pages for all HTTP error codes:
|
|
|
|
| Code | Status |
|
|
|------|--------|
|
|
| 400 | Bad Request |
|
|
| 401 | Unauthorized |
|
|
| 403 | Forbidden |
|
|
| 404 | Not Found |
|
|
| 405 | Method Not Allowed |
|
|
| 408 | Request Timeout |
|
|
| 409 | Conflict |
|
|
| 410 | Gone |
|
|
| 415 | Unsupported Media Type |
|
|
| 422 | Unprocessable Entity |
|
|
| 429 | Too Many Requests |
|
|
| 500 | Internal Server Error |
|
|
| 502 | Bad Gateway |
|
|
| 503 | Service Unavailable |
|
|
| 504 | Gateway Timeout |
|
|
|
|
For FastAPI, `RequestValidationError` (422) is also caught separately.
|
|
|
|
## Linking asw.css
|
|
|
|
By default, styles are inlined — no external dependencies needed. If your app already serves `asw.css`, link it instead:
|
|
|
|
```python
|
|
register_asw_errors(app, css_url="/static/asw.css")
|
|
```
|
|
|
|
The pages will then use your full theme including custom fonts.
|
|
|
|
## Custom app name
|
|
|
|
The nav bar shows your app's name. Override it:
|
|
|
|
```python
|
|
register_asw_errors(app, app_name="My Service")
|
|
```
|
|
|
|
Flask auto-detects from `app.name`; FastAPI from `app.title`. Both fall back to sensible defaults.
|
|
|
|
## Standalone HTML generation
|
|
|
|
The `error_html()` function is also exported if you need to generate pages directly:
|
|
|
|
```python
|
|
from asw_errors import error_html
|
|
|
|
html = error_html(404, path="/missing/route")
|
|
html = error_html(500, css_url="/static/asw.css", app_name="My API")
|
|
```
|
|
|
|
## No dependencies at module level
|
|
|
|
Flask and FastAPI are imported lazily inside `register_asw_errors()` — so this file can live in a project that uses either framework without both installed.
|