Přeskočit na hlavní obsah

Error Handling System

The Mattermost API Client includes sophisticated error handling capabilities to provide meaningful feedback when API operations fail.

User-Friendly Error Messages​

When API calls fail, the system:

  • Attempts to retrieve detailed error information from Mattermost's logs
  • Looks for a translated error message in EspoCRM's language system
  • Presents a clean, formatted error to end users

This prevents technical API errors from confusing users while still providing actionable information.

Fallback Mechanism​

The system supports optional fallback operations when specific errors occur. For example, if a token creation fails because a token already exists, you could configure a fallback to retrieve the existing token instead.


Technické informace​

The error handling is implemented in ApiExceptionUtil, which provides these key methods:

tryExecuteThrowForFrontend()​

  • Parameters:
  • callable $operation: The API operation to execute
  • string|null $fallbackOn: Optional error reason that triggers fallback
  • callable|null $fallbackOperation: Operation to execute if fallback condition matches
  • Returns: Mixed result from operation or fallback
  • Throws:
  • ErrorSilent with formatted error for frontend display
  • Original exception if not an ApiException

getTranslatedMessage()​

  • Parameters:
  • LogInfo|null $logInfo: Error details from Mattermost
  • Returns: Translated error message or null

This class integrates with EspoCRM's Language system for translations and ErrorSilent for user-friendly error presentation.