Skip to main content

Error Handling

Handle errors consistently so clients receive clear responses and logs remain actionable.

Handler-level errors​

Return HTTP status codes that match the failure:

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

API responses​

For API endpoints, prefer structured error responses and keep messages developer-friendly while avoiding sensitive details.