Commit d8984d35 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Merge branch 'default-app-404' into 'v0.10.0'

Added a more friendly default 404 response for the nomad app.

See merge request !277
parents fd8e62d2 bac3146d
Pipeline #95573 passed with stages
in 26 minutes and 10 seconds
......@@ -34,3 +34,4 @@ parser.osio.log
......@@ -17,8 +17,11 @@
from fastapi import FastAPI, status, Response
from fastapi.responses import JSONResponse, HTMLResponse
from fastapi.middleware.wsgi import WSGIMiddleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.exceptions import HTTPException as StarletteHTTPException
from fastapi.exception_handlers import http_exception_handler as default_http_exception_handler
from nomad import config, infrastructure
......@@ -70,3 +73,57 @@ async def startup_event():
async def http_exception_handler(request, exc):
if exc.status_code != 404:
return await default_http_exception_handler(request, exc)
accept = request.headers['accept']
except Exception:
accept = None
if accept is not None and 'html' in accept:
return HTMLResponse(status_code=404, content=f'''
<h1>NOMAD app</h1>
{'<br/>'.join(f'{key}: {value}' for key, value in config.meta.items())}
<a href="{app_base}/api">NOMAD API v0</a><br/>
<a href="{app_base}/api/v1/extensions/docs">NOMAD API v1</a><br/>
<a href="{app_base}/optimade/v1/extensions/docs">Optimade API</a><br/>
<a href="{app_base}/dcat">DCAT API</a><br/>
return JSONResponse(status_code=404, content={
'detail': 'Not found',
'info': {
'app': config.meta,
'apis': {
'v0': {
'root': f'{app_base}/api',
'dashboard': f'{app_base}/api',
'v1': {
'root': f'{app_base}/api/v1',
'dashboard': f'{app_base}/api/v1/extensions/docs',
'documentation': f'{app_base}/api/v1/extensions/redoc',
'optimade': {
'root': f'{app_base}/optimade/v1',
'dashboard': f'{app_base}/optimade/v1/extensions/docs'
'dcat': {
'root': f'{app_base}/dcat',
'dashboard': f'{app_base}/dcat'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment