Skip to main content

Error Code Reference

The Entrupy Android SDK uses a comprehensive error code system to communicate various failure conditions. Understanding these error codes is essential for proper error handling and debugging.

Error Code Structure

All SDK errors are represented by the EntrupyErrorCode enum and include both a code and a descriptive message.

enum class EntrupyErrorCode {
// Authorization errors
AUTHORIZATION_EXPIRED,
AUTHORIZATION_INVALID,
USER_NOT_AUTHORIZED,

// Network errors
NETWORK_ERROR,
NETWORK_TIMEOUT,
SERVER_ERROR,

// Capture errors
CAMERA_PERMISSION_DENIED,
STORAGE_PERMISSION_DENIED,
CAPTURE_TIMEOUT,
CAPTURE_CANCELLED,

// Configuration errors
CONFIGURATION_ERROR,
INVALID_METADATA,

// General errors
UNKNOWN_ERROR,
SDK_NOT_INITIALIZED
}

Authorization Errors

AUTHORIZATION_EXPIRED

Code: AUTHORIZATION_EXPIRED
Description: The user's authorization token has expired.

Common Causes:

  • Token has reached its expiration time
  • User session was invalidated server-side

Recommended Action:

// Re-authorize the user
val authRequest = EntrupySdk.getInstance().generateAuthorizationRequest()
// Send to backend and complete authorization flow

AUTHORIZATION_INVALID

Code: AUTHORIZATION_INVALID
Description: The authorization token is malformed or invalid.

Common Causes:

  • Token was corrupted during transmission
  • Token was generated with incorrect parameters
  • Backend returned an invalid token

Recommended Action:

// Generate a new authorization request
val authRequest = EntrupySdk.getInstance().generateAuthorizationRequest()
// Re-authenticate with backend

USER_NOT_AUTHORIZED

Code: USER_NOT_AUTHORIZED
Description: No valid authorization session exists.

Common Causes:

  • User has never been authorized
  • Session was cleared without re-authorization
  • SDK was not properly initialized

Recommended Action:

// Check if user is authorized
if (!EntrupySdk.getInstance().isAuthorizationValid()) {
// Perform full authorization flow
performUserAuthorization()
}

Network Errors

NETWORK_ERROR

Code: NETWORK_ERROR
Description: General network communication failure.

Common Causes:

  • No internet connection
  • DNS resolution failure
  • Network configuration issues

Recommended Action:

// Check network connectivity
if (isNetworkAvailable()) {
// Retry the operation
retryOperation()
} else {
// Show network error to user
showNetworkError()
}

NETWORK_TIMEOUT

Code: NETWORK_TIMEOUT
Description: Network request timed out.

Common Causes:

  • Slow network connection
  • Server overload
  • Network congestion

Recommended Action:

// Implement exponential backoff
if (retryCount < maxRetries) {
delay(retryDelay * (2.pow(retryCount)))
retryOperation()
} else {
showTimeoutError()
}

SERVER_ERROR

Code: SERVER_ERROR
Description: Entrupy servers returned an error.

Common Causes:

  • Server maintenance
  • API rate limiting
  • Internal server errors

Recommended Action:

// Log error for debugging
Log.e("Entrupy", "Server error: $message")
// Show generic error to user
showServerError()

Capture Errors

CAMERA_PERMISSION_DENIED

Code: CAMERA_PERMISSION_DENIED
Description: User denied camera permission.

Common Causes:

  • User explicitly denied permission
  • Permission was revoked in settings

Recommended Action:

// Guide user to settings
showPermissionDialog(
title = "Camera Permission Required",
message = "Please enable camera access in Settings to continue.",
positiveAction = { openAppSettings() }
)

STORAGE_PERMISSION_DENIED

Code: STORAGE_PERMISSION_DENIED
Description: User denied storage permission.

Common Causes:

  • User explicitly denied permission
  • Permission was revoked in settings

Recommended Action:

// Guide user to settings
showPermissionDialog(
title = "Storage Permission Required",
message = "Please enable storage access in Settings to continue.",
positiveAction = { openAppSettings() }
)

CAPTURE_TIMEOUT

Code: CAPTURE_TIMEOUT
Description: User did not complete capture within the time limit.

Common Causes:

  • User left the capture flow idle
  • Capture session exceeded 2-hour limit

Recommended Action:

// Offer to restart capture
showTimeoutDialog(
message = "Capture session timed out. Would you like to try again?",
positiveAction = { startCaptureFlow() }
)

CAPTURE_CANCELLED

Code: CAPTURE_CANCELLED
Description: User cancelled the capture process.

Common Causes:

  • User pressed back button
  • User explicitly cancelled

Recommended Action:

// Handle gracefully - user chose to cancel
Log.i("Entrupy", "User cancelled capture")
// No action needed, user made a conscious choice

Configuration Errors

CONFIGURATION_ERROR

Code: CONFIGURATION_ERROR
Description: SDK configuration is invalid or missing.

Common Causes:

  • SDK not properly initialized
  • Invalid API key
  • Missing required configuration

Recommended Action:

// Re-initialize SDK
Entrupy.init(context, apiKey)
// Verify configuration

INVALID_METADATA

Code: INVALID_METADATA
Description: Item metadata provided is invalid or missing required fields.

Common Causes:

  • Missing required fields (brand, style_name)
  • Invalid data types
  • Malformed metadata structure

Recommended Action:

// Validate metadata before submission
if (isValidMetadata(itemMetadata)) {
startCapture(itemMetadata)
} else {
showValidationError("Please provide valid item information")
}

General Errors

UNKNOWN_ERROR

Code: UNKNOWN_ERROR
Description: An unexpected error occurred.

Common Causes:

  • Unhandled exception
  • SDK internal error
  • Platform-specific issues

Recommended Action:

// Log error for debugging
Log.e("Entrupy", "Unknown error: $message")
// Show generic error to user
showGenericError()

SDK_NOT_INITIALIZED

Code: SDK_NOT_INITIALIZED
Description: SDK was not properly initialized before use.

Common Causes:

  • Forgot to call Entrupy.init()
  • Initialization failed silently

Recommended Action:

// Ensure SDK is initialized
if (!Entrupy.isInitialized()) {
Entrupy.init(context, apiKey)
}

Error Handling Best Practices

1. Always Check Error Codes

override fun onFailure(errorCode: EntrupyErrorCode, message: String) {
when (errorCode) {
EntrupyErrorCode.AUTHORIZATION_EXPIRED -> handleAuthExpired()
EntrupyErrorCode.NETWORK_ERROR -> handleNetworkError()
EntrupyErrorCode.CAMERA_PERMISSION_DENIED -> handlePermissionDenied()
else -> handleGenericError(errorCode, message)
}
}

2. Implement Retry Logic

private fun retryWithBackoff(operation: () -> Unit, maxRetries: Int = 3) {
var retryCount = 0
val retryOperation = {
if (retryCount < maxRetries) {
retryCount++
delay(1000L * retryCount) // Exponential backoff
operation()
} else {
showMaxRetriesExceeded()
}
}
retryOperation()
}

3. User-Friendly Error Messages

private fun getUserFriendlyMessage(errorCode: EntrupyErrorCode): String {
return when (errorCode) {
EntrupyErrorCode.AUTHORIZATION_EXPIRED -> "Your session has expired. Please log in again."
EntrupyErrorCode.NETWORK_ERROR -> "Please check your internet connection and try again."
EntrupyErrorCode.CAMERA_PERMISSION_DENIED -> "Camera access is required. Please enable it in Settings."
else -> "An unexpected error occurred. Please try again."
}
}

4. Logging for Debugging

override fun onFailure(errorCode: EntrupyErrorCode, message: String) {
Log.e("Entrupy", "Error: $errorCode - $message")
// Handle error appropriately
}