packagehttperrimport("errors""net/http""github.com/charmbracelet/log")typehttpErrorstruct{errerrorstatusint}func(hhttpError)Error()string{returnh.err.Error()}func(hhttpError)Unwrap()error{returnh.err}// Error returns a generic 500 error
funcError(errerror)httpError{returnStatus(err,http.StatusInternalServerError)}// Status returns a set status with the error
funcStatus(errerror,statusint)httpError{returnhttpError{err:err,status:status}}// Handler transforms an http handler + error into a stdlib handler
funcHandler(fnfunc(whttp.ResponseWriter,r*http.Request)error)http.HandlerFunc{returnfunc(whttp.ResponseWriter,r*http.Request){iferr:=fn(w,r);err!=nil{status:=http.StatusInternalServerErrorvarhttpErrhttpErroriferrors.As(err,&httpErr){status=httpErr.status}log.Error(err)http.Error(w,http.StatusText(status),status)}}}