1
0
mirror of https://github.com/JarvyJ/HomeIntent.git synced 2022-02-11 01:01:05 +03:00
Files
homeIntent-rhasspy-integrat…/ui/exceptions.py
Jarvy Jarvison 86168572db Get Home Intent settings page working (#83)
* removed link to docs for custom components

* we're now playing some audio from the settings page!

* can now upload and set_default the custom sounds

* refactored a lot of the python backend and created a custom exception

* hide rhasspy from component list (it's settings are mostly handled by the home intent page or are used by advanced users)

* renamed alarm2.wav to test-sound.wav
2021-09-17 23:52:41 -05:00

30 lines
1002 B
Python

from typing import Any, Dict, Optional
from fastapi import HTTPException, Request
from fastapi.responses import JSONResponse
class HomeIntentHTTPException(HTTPException):
def __init__(
self,
status_code: int,
title: str,
detail: Any = None,
links_about: str = None,
headers: Optional[Dict[str, Any]] = None,
) -> None:
super().__init__(status_code=status_code, detail=detail, headers=headers)
self.title = title
self.links_about = links_about
async def http_exception_handler(request: Request, exc: HomeIntentHTTPException) -> JSONResponse:
error_object = {"title": exc.title, "detail": exc.detail, "status_code": f"{exc.status_code}"}
if exc.links_about:
error_object["links"] = {"about": exc.links_about}
if exc.headers:
return JSONResponse(error_object, status_code=exc.status_code, headers=exc.headers)
else:
return JSONResponse(error_object, status_code=exc.status_code)