MATIH Platform is in active MVP development. Documentation reflects current implementation status.
2. Architecture
API Design
Error Handling

Error Handling

The MATIH Platform uses a structured error response format across all services. Every error response follows the same envelope structure, uses typed error codes, and includes enough context for debugging without leaking sensitive internal details.


Error Response Structure

All error responses use the standard envelope with success: false:

{
  "success": false,
  "error": {
    "code": "RESOURCE_NOT_FOUND",
    "category": "CLIENT_ERROR",
    "message": "Dashboard with ID 'dash-xyz' not found",
    "details": {
      "resourceType": "Dashboard",
      "resourceId": "dash-xyz"
    }
  },
  "metadata": {
    "timestamp": "2026-02-12T10:30:00Z",
    "requestId": "req-abc-123",
    "version": "v1"
  }
}

Error Categories

CategoryHTTP Status RangeDescription
CLIENT_ERROR400-499The request was malformed, unauthorized, or targeted a missing resource
SERVER_ERROR500-599An internal error occurred that was not caused by the client
VALIDATION_ERROR400Input validation failed
AUTHORIZATION_ERROR401, 403Authentication or permission failure

Error Codes

Error CodeHTTP StatusDescription
VALIDATION_FAILED400Request body failed schema validation
INVALID_PARAMETER400Query parameter has invalid value
UNAUTHORIZED401Missing or invalid JWT token
TOKEN_EXPIRED401JWT access token has expired
FORBIDDEN403Authenticated but lacks required permission
TENANT_MISMATCH403Attempted to access a resource from another tenant
RESOURCE_NOT_FOUND404Requested resource does not exist
CONFLICT409Resource already exists or concurrent modification
RATE_LIMITED429Per-tenant rate limit exceeded
INTERNAL_ERROR500Unhandled internal error
SERVICE_UNAVAILABLE503Downstream service is unreachable

GlobalExceptionHandler

The GlobalExceptionHandler in commons-java catches all exceptions and translates them to structured error responses. This ensures that no unhandled exception leaks stack traces or internal details to the client.

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleUnhandledException(Exception ex) {
    log.error("Unhandled exception", ex);
    return ResponseEntity.status(500).body(
        ErrorResponse.of(ErrorCode.INTERNAL_ERROR, "An internal error occurred")
    );
}

Exception Mapping

Exception TypeError CodeHTTP Status
MethodArgumentNotValidExceptionVALIDATION_FAILED400
IllegalArgumentExceptionINVALID_PARAMETER400
AuthenticationExceptionUNAUTHORIZED401
AccessDeniedExceptionFORBIDDEN403
ResourceNotFoundExceptionRESOURCE_NOT_FOUND404
DataIntegrityViolationExceptionCONFLICT409
RateLimitExceededExceptionRATE_LIMITED429
Exception (catch-all)INTERNAL_ERROR500

Validation Errors

Validation errors include field-level details:

{
  "success": false,
  "error": {
    "code": "VALIDATION_FAILED",
    "category": "VALIDATION_ERROR",
    "message": "Request validation failed",
    "details": {
      "fieldErrors": [
        {
          "field": "name",
          "message": "must not be blank"
        },
        {
          "field": "email",
          "message": "must be a valid email address"
        }
      ]
    }
  }
}

Error Handling in Python Services

Python services (FastAPI) use a similar pattern with Pydantic validation and custom exception handlers:

@app.exception_handler(ResourceNotFoundException)
async def resource_not_found_handler(request, exc):
    return JSONResponse(
        status_code=404,
        content={
            "success": False,
            "error": {
                "code": "RESOURCE_NOT_FOUND",
                "category": "CLIENT_ERROR",
                "message": str(exc)
            }
        }
    )

Security-Sensitive Errors

The platform follows these principles for security-sensitive errors:

PrincipleImplementation
No stack traces in responsesGlobalExceptionHandler catches all exceptions
No internal details leakageError messages are user-friendly, not technical
Generic auth errorsLogin failures return generic "invalid credentials" message
Tenant isolation violations loggedCross-tenant access attempts trigger security alerts

Related Pages