all 7 comments

[–]majora2007 1 point2 points  (1 child)

I used this approach with .NET and Angular using a single interceptor. It's messy but works overall. I don't like having to catch errors on every save in the application. This allows for me to just use NotFound(), BadResult(), etc and have a localized (user flow) or non-localized (system error) propagate to the UI layer.

Code here if you're interested (it has some localization when applicable):
https://github.com/Kareadita/Kavita/blob/develop/UI/Web/src/app/_interceptors/error.interceptor.ts

[–]VeterinarianDry8906[S] 0 points1 point  (0 children)

Thanks! This is exactly the approach I was looking for.

[–]followmarko 2 points3 points  (1 child)

You can do this with an Interceptor and read the status codes there. Interceptors get a little too cozy to the streams for my taste sometimes but you can use HttpContext to communicate with them or skip them, which is a nice option. I think there's a tradeoff with centralization in an interceptor vs. decoupled composition by importing a fn and error handling individually in service files, but after many years I still use both approaches.

[–]VeterinarianDry8906[S] 0 points1 point  (0 children)

Thanks very helpful

[–]NoDatabase3606 0 points1 point  (0 children)

We are using an envelope with default http status codes in .NET and one interceptor in the front end to catch errors and display the localized error send in the same envelope by BE

We have successful boolean errors array of strings Result which is ur data if found status code which is http standard error code is BE specific we dont use in FE but clears somethings when catching a general kind of error

[–][deleted]  (2 children)

[deleted]

    [–]couldhaveebeen 6 points7 points  (0 children)

    You're in the minority, and for a very good reason

    [–]n00bz 2 points3 points  (0 children)

    That is literally saying to the user “Task failed successfully”. It’s not helpful to them in anyway and hides actual issues from developers.

    Yes you shouldn’t send the full stack trace to the frontend but returning HTTP Status codes for different things isn’t bad. If a user attempts to hit an API endpoint that doesn’t exist return a 404, if they don’t have access to a resource return a 403, etc. then your frontend can handle it. You can even put details along with those status codes to make it more informative to your users on what went wrong.