Skip to main content

What is best practice for global error-handling in the JS-SDK?

Hi Henning,

There are two approaches to global error handling in the JavaScript SDK. For a React application, it is recommended to use a component around all your code and store the errors inside a context (data storage) shown in this component.  For a NodeJS application, it is recommended to use a middleware that will catch the error and highlight it.

For Cognite API related errors, we do have some documentation on that in the API reference doc (https://docs.cognite.com/api/v1/

I hope this helps

Regards

Omar


We have the error-boundary in place in our React-application, but it does not deal well with async-errors outside of React-code. You can in theory rethrow the error-messages and have them caught, but I couldn’t get this approach to work.

Also I would very much like not having to try-catch every single api-call we make.

I couldn’t find anything in the documentation that seemed relevant. Which part would you have me look at?


Hi Henning.

For doing global promise rejection you can use this link. This will enable you to handle all the unhandled promise rejections. When it comes to having similar functionality in the SDK, this is valuable insight as we currently do not offer such a thing.

Let me know if this helps

Kindest Regards

Omar 


Awesome! I’ll try it out!


Hi Henning. Were you able to resolve this issue? Wanted to follow up to see how it went


Haven’t had a chance to implement it yet. I’ll let you know as soon as possible :)


Did exactly what I needed. Thank you :)


Reply