ESP32-sveltekit
ESP32-sveltekit copied to clipboard
Error Handling in API Requests
Problem
Currently if a request fails the end user does not get notified of the result of the request.
Most fetch call is wrapped in a try catch that silently logs the error with console.error().
Proposal
An api service, which handles the unsuccessful requests and return a typed response. Something like:
await get<Networks>('/rest/listNetworks')
The service should:
- Fetch the data with appropriate authentication
- Notify the user (maybe via toast service) of any errors that occurred
- Cast the json response to T type
- return the data
Let me know if you are interested in the proposed feature.
I'm not a professional developer and used this project to learn JS/TS. So yes, there is a lot to improve.
I would also be interested in a more graceful behavior of the front end when the connection to the ESP is lost temporarily, or the ESP restarts.