Error Handling

Learn how to handle errors and troubleshoot common issues.

Error Response Format

When an error occurs, the API returns a JSON response with details about the error:

Error Response
{
  "success": false,
  "error": {
    "code": "AUTHENTICATION_FAILED",
    "message": "API key not found or has been revoked.",
    "hint": "Check your API key or generate a new one from the dashboard."
  }
}

HTTP Status Codes

StatusMeaning
200Success - Request completed successfully
400Bad Request - Invalid parameters or missing required fields
401Unauthorized - Missing or invalid API key
413Payload Too Large - File exceeds maximum size (50MB)
429Too Many Requests - Rate limit exceeded
500Internal Server Error - Something went wrong on our end

Common Error Codes

CodeDescriptionSolution
AUTHENTICATION_REQUIREDNo API key providedAdd Authorization header
AUTHENTICATION_FAILEDInvalid or revoked API keyCheck key or generate new one
INVALID_PDFFile is not a valid PDFEnsure file is a valid PDF
FILE_TOO_LARGEFile exceeds 50MB limitCompress or split the file
RATE_LIMIT_EXCEEDEDMonthly limit reachedWait for reset or upgrade
API_KEY_WRONG_DOMAINAPI key used on main domainUse api.morphopdf.com

Best Practices

  • 1.Always check the status code - Don't assume success, check the HTTP status code first.
  • 2.Parse error responses - The error object contains useful debugging information.
  • 3.Implement retries for 5xx errors - Server errors are usually temporary, retry with exponential backoff.
  • 4.Don't retry 4xx errors - Client errors require fixing the request before retrying.