Consistent Error Format

  1. Rate Limiting
  2. JWT Authentication
  3. Idempotency
  4. API Keys
  5. API Versioning
  6. Pagination
  7. Consistent Error Format
Client
/orders
/users
/payments

Before

// Gateway A throws a string, Gateway B a numeric code,
// Gateway C its own exception shape —
// checkout has to know all three
try {
    $this->gateway->charge($amount);
} catch (StripeException|PaypalError|KlarnaFault $e) {
    return response()->json(['error' => $e->getMessage()], 500);
}

After

class ApiExceptionHandler
{
    public function render(Throwable $e): JsonResponse
    {
        $status = $e instanceof ValidationException ? 422 : 500;

        return response()->json([
            'error' => ['code' => $status, 'message' => $e->getMessage()],
        ], $status);
    }
}
// every endpoint's failure now shares the same {error: {code, message}} shape
{CC}