Any way to catch errors in the monday.api() promise?


  • Make an api request (e.g. { me { name } }) to something you don’t have a scope for (say me:read)
  • Try to catch the error using the promise error callback (e.g. .then(res => { /*handled*/ }, err => { console.error(err); })

It’d be nice if we could receive error messages and handle/present them to users in an appropriate fashion.

Hey @anderslyman.
AFAIK error is meant to be called when there’s an actual error on a lower level (i.e. connection problems). Errors returned by API are simple HTTP 200 responses containing a “error” string, so they aren’t caught as failures.

Yes, Rob is exactly right.

The GraphQL specification recommends using error codes only for transport-level errors. For example, a bad request (400) or a gateway error (502).

Meanwhile, the GraphQL logic is an application layer, so any errors on originating from the application logic (such as a board ID missing or parse error) will still result in a 200. As such, please inspect the “errors” key to check for errors and not the status code.

1 Like

That makes sense, however if there is a value in the errors key, it doesn’t make it into the success callback either.

For example: .then(res => { console.log(res); });
Results in this response in the Network tab (with a 200 status as you mentioned): {"errors":[{"message":"Permission Denied! Your token doesn't grant access to boards:read"}}

But does not result in any console output.

Alright, so I did some digging…

The Monday SDK is not sending XHR requests, it’s simply posting to the iframe parent.
The parent receives those messages and handles the XHR requests.
ALL errors are intercepted by the parent and not passed along to the client.

e.g. as-is, no errors can be intercepted by the client.

I’m looking into authenticating on my own and handling the XHRs myself to get around this limitation… Will post back when I know more.

Also not possible (or at least not recommended).

You’d have to include an api token with your code, which has a number of problems.
You could, in theory, setup an oauth redirect flow, but making that work from an inside an iframe without a host to redirect to doesn’t really work.

Long story short, no error-handling is possible with the sdk.

Hopefully this changes in the future.