| 262 | } |
| 263 | |
| 264 | func writeError(w http.ResponseWriter, err error) { |
| 265 | var statusErr httpStatusError |
| 266 | if errors.As(err, &statusErr) { |
| 267 | http.Error(w, statusErr.Error(), statusErr.code) |
| 268 | return |
| 269 | } |
| 270 | if errors.Is(err, vault.ErrPathEscape) { |
| 271 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 272 | return |
| 273 | } |
| 274 | log.Printf("handler error: %v", err) |
| 275 | http.Error(w, "internal server error", http.StatusInternalServerError) |
| 276 | } |
| 277 | |
| 278 | func readJSON[T any](r *http.Request, out *T) error { |
| 279 | return json.NewDecoder(r.Body).Decode(out) |