How to properly translate HttpExceptions in the Frontend with Angular?

264 Views Asked by At

We have a complex business logic where we raise several HTTPExceptions with FastAPI if an error occurs. When we raise an exception we define a status code and a detail error message. The problem is that this error message is in english but our application has a german interface and we would like to display this error message translated to german in a toastr.

Unfortunately FastAPI doesn't describe what to do if you want to display the detail error message in another language so I was wondering what the best way would be to show a translated error message when we raise said HttpExceptions.

A HTTPException with FastAPI looks somewhat like this:

raise HTTPException(
    status_code=HTTP_403_FORBIDDEN, detail=PERMISSION_ERROR
)

We can additionally maybe add some custom headers but that's basically it.

0

There are 0 best solutions below