Skip to content

Add httperr package for HTTP status code-aware errors - #4

Merged
JAORMX merged 1 commit into
mainfrom
add-errors-package
Feb 2, 2026
Merged

JAORMX merged 1 commit into
mainfrom
add-errors-package

Conversation

@JAORMX

@JAORMX JAORMX commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Graduate the errors package from toolhive as httperr - a more descriptive name for HTTP status code-aware error handling
  • Second Tier 1 package per THV-0032 RFC
  • Provides CodedError type that carries HTTP status codes through the error chain
  • Full support for errors.Is() and errors.As() via Unwrap()
  • Comprehensive package documentation with usage examples

API

// Create a new error with status code
err := httperr.New("not found", http.StatusNotFound)

// Wrap existing error with status code
err := httperr.WithCode(err, http.StatusBadRequest)

// Extract status code from error chain
code := httperr.Code(err) // Returns 500 if no CodedError found

Test plan

  • task lint passes
  • task license-check passes
  • task test passes with race detection

🤖 Generated with Claude Code

Graduate the errors package from toolhive to toolhive-core as httperr,
a more descriptive name for HTTP status code-aware error handling.

This package provides:
- CodedError type that wraps errors with HTTP status codes
- WithCode() to wrap existing errors with a status code
- Code() to extract status codes from error chains
- New() convenience function for creating coded errors
- Full support for errors.Is() and errors.As() via Unwrap()

The package uses only standard library dependencies and is ideal for
centralized API error handling.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@JAORMX
JAORMX merged commit 3b9fd91 into main Feb 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants