Error Handling
GraphQL does not return a 400 response status code when a request is invalid. Instead, Postpone's GraphQL API returns specific attributes for all mutations to help you understand what went wrong and how to fix it.
Error Response Structure
All mutations in the Postpone API return the following attributes:
field
, message
, and code
properties.Validation Errors
Validation errors provide detailed information about why a mutation failed. Each validation error object contains:
Example: Missing Required Fields
When creating a Reddit post without providing required content:
{
"data": {
"scheduleRedditPost": {
"success": false,
"errors": [
{
"field": "content",
"message": "Either link or content is required for a Reddit post",
"code": "LINK_OR_CONTENT_REQUIRED"
}
]
}
}
}
Example: Invalid Field Values
When providing invalid data for specific fields:
{
"data": {
"scheduleRedditPost": {
"success": false,
"errors": [
{
"field": "title",
"message": "Title must be between 1 and 300 characters",
"code": "INVALID_LENGTH"
},
{
"field": "scheduledAt",
"message": "Scheduled time must be in the future",
"code": "INVALID_DATE"
}
]
}
}
}
GraphQL Errors vs Mutation Errors
It's important to distinguish between GraphQL-level errors and mutation-level errors:
GraphQL Errors
These occur at the GraphQL parsing/execution level and are returned in the errors
field of the root response:
{
"errors": [
{
"message": "Cannot query field 'invalidField' on type 'Post'",
"locations": [{"line": 3, "column": 5}]
}
]
}
Mutation Errors
These are business logic errors returned within the mutation's response:
{
"data": {
"scheduleRedditPost": {
"success": false,
"errors": [
{
"field": "title",
"message": "Title is required",
"code": "REQUIRED_FIELD"
}
]
}
}
}
Always check both levels when handling API responses.