Complexity Budget Exhausted, try catch error

Hi there,

Greetings!
Hope you are doing well.

We have some questions related to monday.com API’s response errors that we are receiving.

We are receiving errors in monday.com response while doing the import/update items process using GraphQL API’s. We are getting the following message.

“Complexity budget exhausted, query cost 30001 budget remaining 19834 out of 5000000 reset in 27 seconds”

We are using monday.com custom application and GraphQL API.
We are trying to import ADD/UPDATE/DEL 10k to 20k items using CSV files at a time in Clients Code.
This is the first time we are receiving errors like “Complexity budget exhausted, query cost 30001 budget remaining 19834 out of 5000000 reset in 28 seconds”. So, do you have any suggestions OR why we received this type of error?

Is there is any way to catch this Complexity Budget Exhausted error in code inside try catch block when this error comes, we can stop this process for 30-60 sec then, after 60 sec again start process?

Is it possible??? OR how we can catch this error?

Best,
Aniket

hi @Aniket_Katre3

This API “error” is thrown because you hit the 5M complexity limit with your API query. “Error” is between quotes as it is not really an error in the sense you can catch it. The API call went fine (hence there is no error to catch) but the response from the API contains the error. Therefore you can’t “catch” it inside a try/catch. You need to inspect the data returned from the API (as is the case with all kind of other API errors) and act upon in in your code.

If this occurs during a read (query) the only solution is to use pagination. If this occurs during a write (mutation) you need to time out in your app. Be careful that if you are using shortLivedTokens the token will probably be expired after your timeout. The best way to solve this is to implement a slow dripping queue. As you know what the app is doing you can calculate the “speed” the queue needs to drip.

It the app updates just one cell per posts you can use this calculation. A single cell update bares a cost of 30.001 (I see that also from your post). So with 5M credits every minute, you can do 5M/30.001 = 166,6 single cell updates per minute. That implies the the queue should drip one post every 360 ms to prevent hitting this complexity limit.

Hey @basdebruin

Thanks for quick response,

As you told, we can’t catch this Complexity budget error, But still I would like to know can we go with below approach,

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))
// below logMessage is variable inside we got error message
      logMessage = err.toString() + logMessage;
      if(logMessage.includes("Complexity budget exhausted, query cost")){
        logMessage="Complexity Error comes from monday.com API wait for 60 sec";
        await delay(60000);
      }

I don’t know this will work or not but still I need your suggestion here if we can catch or make this condition to pause the import or Add item process.

With your response I have some question,

with 5M credits every minute, you can do 5M/30.001 = 166,6 single cell updates per minute

I didn’t understand this can you elaborate ?

Best
Aniket :slight_smile:

hi @Aniket_Katre3

That piece of code might work (or not :slight_smile:). This will log a message and delay “somewhere”. Where do you plan to use this delay? If you plan to put this after the call to

mondayClient.api(query, { variables });

is made you only wait sending the response to the calling function. I don’t see where you are retrying. You need to retry and make sure to call the mondayClient.api after the timeout. If your calling function is using shortLivedTokens you probably end up with an authorization error as the shortLivedToken has a 60 second expiration. Therefore a queueing mechanism is the best solution.

To elaborate on the calculation. You get 5M credits (for both read and write) every 60 seconds. That’s why you see the message from your first post. You consumed all those 5M credits in 33 seconds, hence the message that it will reset in 27 seconds. The message also shows a query costs of 30001 (which is the cost for a single mutation). Because you get 5M credits every 60 seconds, you can do a maximum of 5M/30.001 = 166 mutations per minute before hitting the complexity limit.

See also: Rate Limits

1 Like

Hey @basdebruin

Greetings!
Hope you are doing well.

I need you help in this below
I would like to know the below error status_code
" FetchError: request to https://api.monday.com/v2 failed, reason: connect ETIMEDOUT 104.16.11.42:443"

I unable to get above error Status_code, can you please check from your end or how we can find this error status_code using API playground ??

For ex. I have done some error and find status_code

  1. Complexity error code status_code: 429
COMPLEXITY ERROR
monday services log ******************************************= {
  error_code: 'ComplexityException',
  status_code: 429,
  error_message: 'Complexity budget exhausted, query cost 30001 budget remaining 1772 out of 1000000 reset in 15 seconds',
  error_data: {},
  errors: [
    'Complexity budget exhausted, query cost 30001 budget remaining 1772 out of 1000000 reset in 15 seconds'
  ],
  account_id: 8473802
}

AND 2nd: for incorrect group ID: status_code=404

monday services log ******************************************= {
  error_code: 'ResourceNotFoundException',
  status_code: 404,
  error_message: 'Group not found',
  error_data: {
    resource_type: 'group',
    group_id: 'new_gr',
    board_id: 3566052889,
    error_reason: 'store.monday.automation.error.missing_group'
  }
}

I need your help in below error status_code, I unable to find it

FetchError: request to https://api.monday.com/v2 failed, reason: connect ETIMEDOUT 104.16.11.42:443

Hope you understand what I need here And also help me how do I find with API playground.

Cheers!
Aniket

Hi @Aniket_Katre3

Not entirely sure I understand you correctly. These errors will not trigger the catch of your try… catch as they are not really errors form a communications point of view. The handshake went ok so now it is up to you to analyze the result you got form the API.

Hi @basdebruin

thanks for quick reply,

I’m also trying from my end but, the things is in my code it is not going on try-catch block that’s why I unable to get Status_code of this below error.

FetchError: request to https://api.monday.com/v2 failed, reason: connect ETIMEDOUT 104.16.11.42:443

I too finding the way but, it’s not going on TRY-CATCH so, that we can get the status_code.

If possible monday Developer team can tell us what is the status_code of this above error. Cause this status_code is unique for each error
This will be great help
THANKS!

hi @Aniket_Katre3

I see, but this error is from fetch, not from the monday API. Fetch is not able to connect to the monday API server, so you will see nothing in monday response as the API never got the request.

1 Like

Hi @basdebruin

I got it for Fetch error,
I have one more query, i would like to know below error status_code

"Error: Received timeout from monday.com''s GraphQL API"

For ex. I have done some error and find status_code

  1. Complexity error code status_code: 429
COMPLEXITY ERROR
monday services log ******************************************= {
  error_code: 'ComplexityException',
  status_code: 429,
  error_message: 'Complexity budget exhausted, query cost 30001 budget remaining 1772 out of 1000000 reset in 15 seconds',
  error_data: {},
  errors: [
    'Complexity budget exhausted, query cost 30001 budget remaining 1772 out of 1000000 reset in 15 seconds'
  ],
  account_id: 8473802
}

I need your help in below GraphQL error status_code, I unable to find it

"Error: Received timeout from monday.com''s GraphQL API"

Appreciate your response

Cheers !
Aniket

Hello @Aniket_Katre3!

When you have a timeout error, you will get as a response an HTML formatted response. With 504 Gateway Time-out.

Is that the information you were looking for?

Cheers,
Matias

Hey @Matias.Monday

Thanks for quick response,
I would like to know below error comes from monday.com API ? if yes, for each error monday.com API have unique error status_code, as explained for complexity error status_code is 429.

In the same way i would like to know GraphQL error status_code.

"Error: Received timeout from monday.com''s GraphQL API"

> When you have a timeout error, you will get as a response an HTML formatted response. With 504 Gateway Time-out.
Yes, this I got it, but for this above error too monday.com API have this error status_code, that I need.

Actually with this status_code I’m trying to add condition like when this error comes it should wait and again go for retry iterate function.

Cheers,
Aniket :blush:

Hello again @Aniket_Katre3 and thank you for the explanation,

Timeouts have a separate mechanism, not related to graphQL.

Any request to the system that takes more than 1 minute gets terminated.

You will not get a status_code here.

To avoid getting timeout errors, you can split the query into multiple requests. You might want to take a look into our documentation about it.

I hope that helps!

Cheers,
Matias

1 Like