SweetConnect LogoSweetConnect
Response structure

Error Response Structure

Understanding error responses in the SweetConnect Platform API

Overview

The SweetConnect Platform API uses a structured, consistent error response format across all endpoints. Every error response contains detailed information to help you identify and resolve issues quickly.

Error Response Format

All error responses follow this structure:

{
  "errors": [
    {
      "errorCode": "FileTooLarge",
      "message": "Uploaded file exceeds the maximum allowed size of 10MB. Current file size: 12.5MB.",
      "extension": {
        "maxFileSize": 10,
        "currentFileSize": 12.5
      }
    }
  ]
}

Response Structure

FieldTypeDescription
errorsArrayList of error objects (can contain multiple errors)
errorCodeStringMachine-readable error identifier - use this to handle specific errors programmatically
messageString (optional)Human-readable error description
extensionObject (optional)Additional structured data providing context about the error

HTTP Status Codes

Errors are returned with appropriate HTTP status codes:

Status CodeMeaningExample Error Codes
400 Bad RequestInvalid input or requestBadRequest, FileTooLarge, InvalidMimeType, InvalidLanguageCode
401 UnauthorizedAuthentication required or failedUnauthorized, InvalidToken
403 ForbiddenInsufficient permissionsNoPermission
404 Not FoundResource doesn't existNotFound
409 ConflictResource conflictConflict, SerialNumberAlreadyExists
500 Internal Server ErrorServer-side errorInternalServerError

Error Code Identification

The errorCode field is your primary tool for programmatically handling errors. It provides a consistent, machine-readable identifier that won't change between API versions.

Why Use Error Codes?

✅ Do this:

if (response.errors[0].errorCode === 'FileTooLarge') {
  // Handle file too large error
  const maxSize = response.errors[0].extension.maxFileSize;
  alert(`Please upload a file smaller than ${maxSize}MB`);
}

❌ Don't do this:

// Don't parse message strings - they may change!
if (response.errors[0].message.includes('file exceeds')) {
  // Fragile - message text may change
}

Multiple Errors

A single API response can contain multiple errors when multiple validation issues are detected:

{
  "errors": [
    {
      "errorCode": "InvalidLanguageCode",
      "message": "Language code 'xyz' is not valid",
      "extension": {
        "languageCode": "xyz",
        "validLanguageCodes": ["en", "de", "fr", "es", "it"]
      }
    },
    {
      "errorCode": "FileTooLarge",
      "message": "Uploaded file exceeds the maximum allowed size of 10MB. Current file size: 12.5MB.",
      "extension": {
        "maxFileSize": 10,
        "currentFileSize": 12.5
      }
    }
  ]
}

Benefits:

  • Fix all issues at once instead of one-by-one
  • Better user experience - show all validation errors together
  • Fewer API round-trips

Extension Objects

The extension field provides structured, actionable data about the error. Use this to build intelligent error handling and user feedback.

File Size Error Example

{
  "errorCode": "FileTooLarge",
  "extension": {
    "maxFileSize": 10,
    "currentFileSize": 12.5
  }
}

What you can do:

  • Display file size limit before upload
  • Show exact size vs limit: "12.5MB / 10MB"
  • Calculate percentage: "125% of allowed size"

Asset Type Constraint Example

{
  "errorCode": "AssignAssetTypeConstraint",
  "extension": {
    "assetType": "machine",
    "parentAssetType": "component",
    "allowedParentAssetTypes": ["production-line", "location"]
  }
}

What you can do:

  • Filter dropdown to show only allowed parent types
  • Display: "machines can only be assigned to production-line or location"
  • Prevent invalid selections in UI

Next Steps

On this page