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

Merge branch '754-archive-api-raised-500-if-nan-values-are-present' into 'v1.0.3'

Resolve "Archive API raised 500 if NaN values are present"

See merge request !572
parents 02d8428b 135b6ac8
Pipeline #124030 passed with stages
in 36 minutes and 18 seconds
......@@ -16,10 +16,12 @@
# limitations under the License.
#
from typing import Any
from fastapi import FastAPI, status, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, RedirectResponse
import traceback
import orjson
from nomad import config, utils
......@@ -30,6 +32,13 @@ from .routers import users, entries, materials, auth, info, datasets, uploads, s
logger = utils.get_logger(__name__)
class ORJSONResponse(JSONResponse):
media_type = "application/json"
def render(self, content: Any) -> bytes:
return orjson.dumps(content, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS) # type: ignore
app = FastAPI(
root_path=root_path,
openapi_url='/openapi.json',
......@@ -41,7 +50,8 @@ app = FastAPI(
description=utils.strip(f'''
Please visit the [API section of the NOMAD documentation]({config.api_url(True, 'docs/api.html')})
for a introduction and examples.
'''))
'''),
default_response_class=ORJSONResponse)
app.add_middleware(
CORSMiddleware,
......
Supports Markdown
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