Error responses
A predictable error envelope helps clients handle failure safely.
What it is
A predictable error envelope helps clients handle failure safely.
When to use it
Expose stable codes and safe messages.
Syntax
{"error":{"code":"insufficient_funds","message":"Insufficient funds"}}Example
return response()->json(["error" => [
"code" => "conflict",
"message" => "This operation cannot be applied in the current state",
"request_id" => $requestId,
]], 409);Common mistakes
Never expose SQL, file paths, exception traces, or secret-bearing request data.