Skip to main content

Version Docs Updated

Purpose

A set of rules used to ensure the continuity of MHM Rentiva API services and to report error states in a standardized language.

🚦 API Error Handling and Rate Limiting

The system uses the RateLimiter and ErrorHandler classes both to block malicious attacks (brute-force, DoS) and to return consistent error messages to clients.


πŸ›‘ 1. Rate Limiting​

Rate limits are applied per API key (v1) or IP address (Public).

LayerLimit (Requests/Minute)Result on Excess
Public API30HTTP 429
Authenticated (API Key)60HTTP 429
Admin/internal120HTTP 429

Protections:

  • RateLimiter::check(): Enforces the request limit within defined time windows (Sliding Window).
  • Logging: Limit violations are recorded via AdvancedLogger at the SECURITY_WARNING level.

❌ 2. Standard Error Codes​

All API responses use standard HTTP status codes and custom application error codes.

HTTP CodeApplication CodeDescription
400INVALID_PARAMSMissing or incorrectly formatted parameter.
401AUTH_REQUIREDAuthentication header missing or invalid.
403PERMISSION_DENIEDThe user or key does not have permission for this operation.
404RESOURCE_NOT_FOUNDNo record found with the specified ID.
409STATE_CONFLICTThe operation is incompatible with the resource's current state (e.g., booking an unavailable vehicle).
429RATE_LIMIT_EXCEEDEDPer-minute request limit exceeded.
500INTERNAL_ERRORAn unexpected server error occurred.

πŸ› οΈ 3. Logging and Correlation ID​

The system generates a Correlation ID (e.g., req_abc123) alongside every error response:

  • Developer Tip: Technical error details (stack trace, etc.) are never returned in the error body. Instead, an ID is returned that helps locate the relevant entry in the logs.
  • ErrorHandler::format_error(): Centrally catches, logs, and serves all errors to clients in a safe JSON format.

πŸ“€ 4. Error Response Example​

{
"success": false,
"error": {
"code": "PERMISSION_DENIED",
"message": "Bu işlem için 'rentiva_vendor' yetkisi gereklidir.",
"correlation_id": "err_1773849524"
}
}

Section Summary​

  • RateLimiter protects the system; ErrorHandler standardizes communication.
  • Errors are never returned as raw PHP errors, but as formatted JSON.
  • Correlation ID makes it easy to track production errors.

Changelog​

DateVersionNote
23.04.20264.27.2English translation added.
19.03.20264.21.2Rate limit layers, Application Error Codes, and Correlation ID details added.