When working with PMKIN's GraphQL API, you'll encounter different errors depending on the situation. Let's explore how these errors work and how to handle them effectively.
The most fundamental error you might encounter is an authentication error. If you make a request without proper authentication, the API will return a 401 status code with a straightforward error message:
{
"error": "Unauthorized."
}
Another common scenario is hitting rate limits. If you make too many requests in a short period, the API will return a 429 status code with a message indicating you've exceeded the rate limit:
{
"error": "Rate limit exceeded."
}
For all other cases, the API follows standard GraphQL error conventions. These errors are more detailed and structured, appearing in an errors
array in the response body. Here's what a typical GraphQL error looks like:
{
"errors": [
{
"message": "Error message details",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": ["field", "subfield"],
"extensions": {
"code": "ERROR_CODE"
}
}
]
}
These GraphQL errors can occur for various reasons. You might see a 400 status code if your query syntax is invalid or if you're trying to access fields that don't exist. During query execution, if something goes wrong on the server side, you'll get a 500 status code. Sometimes, you might even get partial successes where some fields resolve correctly while others fail - in these cases, you'll see both data
and errors
in the response.
Each GraphQL error object provides helpful information through its fields. The message
field gives you a human-readable description of what went wrong. The locations
field helps you pinpoint where in your query the error occurred, showing the line and column numbers. The path
field shows you exactly which part of your query failed, and the extensions
field provides additional metadata about the error, including specific error codes.
Remember that GraphQL's error handling is designed to be predictable and informative. By understanding these error patterns, you can build robust error handling into your applications and provide better feedback to your users when things go wrong.