Skip to content

Martini Services Errors

In the Martini Package, we showcase various error handling strategies essential for robust service development. This documentation outlines our approach to managing service errors, ensuring that our APIs maintain consistency and reliability even when unexpected issues arise. Below, find the key implementations you'll encounter within the services folder of our package:

Error Handling Strategies

  1. Service Logic Errors: Learn how to address errors directly stemming from the service logic, such as input validation failures. This section guides you through preemptively catching and handling common mistakes to prevent service disruption.

  2. Exception Handling: Discover the best practices for catching and managing exceptions thrown during service execution. This approach emphasizes the importance of maintaining service availability and integrity under unforeseen circumstances.

  3. Centralized Error Handling: We advocate for the implementation of a dedicated error handling service. By centralizing error management, you can develop a single, reusable error handler that applies across all your services, streamlining the error handling process.

Unified Error Response Model

Our error handling philosophy extends to the API response structure. We ensure that all services adhere to a single error response model, facilitating easier error identification and management. This model includes:

  • A Common Data Model for error responses, allowing for a standardized error structure across JSON or XML formats.
  • Proper Response Codes configuration, ensuring that your APIs return the correct HTTP status codes (e.g., 400 for bad requests, 404 for not found, 500 for internal server errors) alongside the error information.
  • Error Data Mapping, which details the process of associating specific error conditions with the unified data model, enhancing the clarity and utility of error responses.

Practical Demonstration

To see our error handling approaches in action, send requests to the following API endpoints:

  • <martini-host>api/ErrorHandlerAPI/test_error1?input_text=some_text
  • <martini-host>api/ErrorHandlerAPI/test_error2?input_text=some_text
  • <martini-host>api/ErrorHandlerAPI/test_error3?input_text=some_text

Note: The input_text parameter accepts only "foo" or "bar" as valid inputs. Any other input will trigger an error response.

These endpoints are designed to demonstrate the distinct error handling mechanisms in practice, showcasing how to achieve consistency in error responses across your APIs. For further insights into the configuration of these services, refer to the API editor file located in the api folder.