The-Commit-Company / frappe-js-sdk

TypeScript/JavaScript library for Frappe REST API
MIT License
120 stars 43 forks source link

How to globally handle error message from server in single place? #29

Closed frappeerpnext closed 1 year ago

frappeerpnext commented 1 year ago

Hi, How can I globally handle error message from server in a single place. I mean with use .catch every time we send request to frappe server?

Thank

nikkothari22 commented 1 year ago

Well the library is Promise based - so you can create your own wrapper around it using a try catch block and show a popup in your exception handling.

But the library doesn't support any feature to track errors globally since sometimes you might want to chain API calls together.

Alchez commented 1 year ago

@frappeerpnext @nikkothari22 There's no API available for it, but every FrappeApp class instance will have an axios client property that you can use. For error handling, you could add interceptors to the client and handle responses the way you want.