Skip to content

Error page should only apply to ui.page endpointsΒ #5508

@ghbm-itk

Description

@ghbm-itk

First Check

  • I added a very descriptive title here.
  • This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
  • I used the GitHub search to find a similar issue and came up empty.

Example Code

# File1.py
from nicegui import app, ui

@ui.page("/")
def gui():
    ui.label("Hello!")

@app.get("/api")
def api():
    return {"response": "hello from api"}

@app.get("/api_error")
def api():
    return {"response": 1/0}

ui.run()

# File2.py
import requests

result = requests.get("http://127.0.0.1:8080/api_error")
print(result)
print(result.text)

Description

I think the default error page should only apply to ui.page endpoints and not endpoints defined by app.get etc.

It creates a very ugly error response for api users, when they receive the error page as html when not viewed in a browser.
Instead api endpoints should be handled by fastapi's normal error handling.

NiceGUI Version

3.11

Python Version

3.11

Browser

Edge

Operating System

Windows

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugType/scope: A problem that needs fixingreviewStatus: PR is open and needs review

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions