Can you improve error handling?

Hi,

I’ve been using your GraphQL API extensively for a while now and I think it is about time to write you a few sentences about error handling that I think you could improve.

Overall I think your API is working great but when we come to error handling it is very bad (if you ask me).

Usually when using REST API the HTTP status code 200 always means that the request went OK. But this isn’t the case with Monday.com GraphQL API. In almost all cases I am getting HTTP status code 200 but the response then doesn’t contain the expected response. Instead it contains the error message. See the example below:

{"error_message":"This column ID doesn't exist for the board","error_code":"InvalidColumnIdException","error_data":{"column_id":"text2","board_id":null,"error_reason":"store.monday.automation.error.missing_column"},"status_code":200,"account_id":22225094}

If necessary I can copy-paste the request body but for sake of ease I will omit it for now.

The HTTP request has HTTP status code 200 but the response is an error. Why don’t you use HTTP error code 4xx for this use-case? There are plenty of 4xx error codes you can use for this purpose.

In order to handle this kind of error I have to check each and every response like following (Swift code):

if lowercasedDataString.contains("\"error_code\":\"ComplexityException\"".lowercased()) ||
lowercasedDataString.contains("\"error_code\":\"complexityBudgetExhausted\"".lowercased()) ||
lowercasedDataString.contains("\"error_code\":\"ColumnValueException\"".lowercased()) ||
lowercasedDataString.contains("\"status_code\":429".lowercased()) {
... error 1
} else if dataString.contains("\"error_code\":\"ResourceNotFoundException\"") &&
dataString.contains("\"status_code\":404") {
... errror 2
}
...etc.

The example above is just a small code snippet of how my error handling looks like.
And I have to do this for each HTTP request because every request returns with HTTP status code 200. Definitely not the most performant code we can get.
Secondly, I have to rely on searching for error messages that can change at any moment. I.e. if some developer makes a typo then my error checking code won’t work properly anymore.

On the other hand, if you would return this as HTTP status code 4xx then I would do this check only in case of HTTP status code 4xx. Or even better, if you would enumerate each and every error by HTTP status code then I could simply compare them by the code number.

The other part of the problem is the fact that I can’t find the list of all possible errors that your system can throw. This means I simply have to force a lot of different scenarios that would simulate problems and collect all possible errors.
In the end this leads me in the situation where my users end up having errors that I forgot to create. Again, definitely not the best UX you can offer to the users.

Please don’t get me wrong, I appreciate the work you have done with your API and the constant improvements you deliver to us by regular API updates! I would be really happy if you can also make some improvements with error handling :slight_smile:

Thanks,
Josip

One more use-case that is not logical.

I am creating an API call that has invalid column_id (basically a fake column_id). In one scenario I am getting this error:

{
  "error_message": "This column ID doesn't exist for the board",
  "error_code": "InvalidColumnIdException",
  "error_data": { "column_id": "text2", "board_id": null, "error_reason": "store.monday.automation.error.missing_column" },
  "status_code": 200,
  "account_id": 22225094
}

And in other scenario I am getting this one:

{
  "error_message": "Column not found",
  "error_code": "ResourceNotFoundException",
  "error_data": {
    "resource_type": "column",
    "column_id": "date4212",
    "board_id": 6068264184,
    "error_reason": "store.monday.automation.error.missing_column"
  },
  "status_code": 404,
  "account_id": 2092815
}

Why can’t I always get the same error? Then to make things even more confusing, the error_code ResourceNotFoundException is often related to other errors that have different error_messages and the only way how to differentiate the errors is by combining status_code and error_message. This in the end leads to comparing text messages that can change at any time.

Thanks,
Josip

I have heard that in a future (soon) API version they will be start sending GraphQL spec compliant errors for everything (while still sending the non-compliant data alongside for a while to allow a transition).

Along with this, they maybe also being improving the errors themselves. The first one gives us a consistent manner for dealing with them. (It also opens the door for using GraphQL clients which will generate actual exceptions for the errors if you want)

I’d recommend checking queries in the preview and dev versions in the API playground to see if there are any changes in each version. They also will announce in the change log.