Monday.api doesn't return when user is viewer or guest

Hey,

When my board view loads, I’m calling monday api for info about me and board. If the user is an account viewer, I see in the chrome dev console there was an error, but my code never gets it (not with await and not with .then / .catch). The error in the console is:

POST https://eazyapps.monday.com/v2 403
Error: There was an error in response from monday.com graphql API

And if I look at the http response body in the chrome dev console, I see:

{"error_code":"UserUnauthroizedException","status_code":403,"error_message":"The user is unauthorized to use the api_v2","error_data":{"user_id":15943487}}

Related question - I’m trying to figure out if the current user who loaded my board view is a viewer or guest, what’s the best way of doing that? If the api call will return the error above to me, that will be the preferred way I think, since I don’t want to ask for more scopes than needed when installing my app (i.e. users:read).

Thanks,
Ronen

Hey @rbabayoff,

Are you using monday.api() to make the api calls?

And if syou do, are you setting the token yourself, or do you let the monday sdk set it automatically?

Hey @LaurentConroux, yes I’m using monday.api to make the calls, and since its from within the board view, no need to use a token.

It’s not the first time that I ran into the monday api “swallowing” errors without returning. The error is ok, that’s not the problem, but I need to get it back.

Seems like the monday.api is wrapped internally with a catch handler that swallows errors or not using await when calling an async function and therefore the errors are lost.

Hey @rbabayoff,

I see the error in your console seems to include your domain (slug + monday.com) - is the URL you are trying to query against in your application?

If so - could you try querying against our API url instead?

https://api.monday.com/v2/

Let me know if that helps.

-Daniel

1 Like

Hey Daniel,

I don’t control that - I’m using monday.api from the monday sdk, i.e.:

import mondaySdk from "monday-sdk-js";
const monday = mondaySdk();
...
const res = await monday.api(`
query MyQuery($boardId: Int!) {
	me {
    id
    email
    name
  }
...

Daniel,

This is a known issue with the monday sdk that has already been reported previously as an issue in your gihub repo. See here.

Ronen

Hey @rbabayoff,

Apologies! For a moment there I thought you were running into this error through the API rather than the SDK, please disregard :slight_smile: I checked in with the team and propagating API errors through the SDK is actually something on our roadmap that we hope to be tackling soon, but don’t have an ETA just yet.

In terms of figuring out the current user loading the board view - this wouldn’t be possible through an API call right now, it would require making an SDK call.

Let me know if we can further assist!

-Daniel

1 Like

Hey @rbabayoff, thanks for reporting this issue!
The problem with API error propagation was solved in the new version of the SDK (0.1.1)
Just update your dependency and the promise should be rejected when there is an error from the API

image

1 Like

Hi. I am having the same issue. Testing Board View app for a potential viewer, the SDK doesn’t return any data from the board. For “full” board members the app works perfectly.

I understand the discussion about exception catching, but my question is: why would a viewer be unauthorised from reading data via the SDK/API when they are able to see this data in the board itself ? @rbabayoff did you resolve your issue?

Thanks

Hey @VladMonday, so I updated to v0.1.1 and yes, now it throws an exception, but the exception is not an Error instance with details about the error, it’s an empty object without any info, and I’m still not able to know if the user is a viewer or a guest.

What I’d like to get is the error response from the api call so I know if it’s a not authorized error and not some unknown error. This is what I’d like to get back in some fashion (this is the http response from the api which you can also get in the api playground:

{
  "error_code": "UserUnauthroizedException",
  "status_code": 403,
  "error_message": "The user is unauthorized to use the api_v2",
  "error_data": {
    "user_id": 15943487
  }
}

Thanks,
Ronen

1 Like

Same problem here, I’m trying to capture ColumnValueException error code, but it is not returned back to application.

@VladMonday, can monday.api() call return error code in exception?