Charles Iliya Krempeaux d5eea959fb | ||
---|---|---|
LICENSE | ||
README.md | ||
badgateway.go | ||
badrequest.go | ||
clienterror.go | ||
conflict.go | ||
errbadgateway_test.go | ||
errbadrequest_test.go | ||
errconflict_test.go | ||
errexpectationfailed_test.go | ||
errfaileddependency_test.go | ||
errforbidden_test.go | ||
errgatewaytimeout_test.go | ||
errgone_test.go | ||
errhttpversionnotsupported_test.go | ||
errinsufficientstorage_test.go | ||
errinternalservererror_test.go | ||
errlengthrequired_test.go | ||
errlocked_test.go | ||
errloopdetected_test.go | ||
errmethodnotallowed_test.go | ||
errmisdirectedrequest_test.go | ||
errnetworkauthenticationrequired_test.go | ||
errnotacceptable_test.go | ||
errnotextended_test.go | ||
errnotfound_test.go | ||
errnotimplemented_test.go | ||
error.go | ||
errpaymentrequired_test.go | ||
errpreconditionfailed_test.go | ||
errpreconditionrequired_test.go | ||
errproxyauthrequired_test.go | ||
errrequestedrangenotsatisfiable_test.go | ||
errrequestentitytoolarge_test.go | ||
errrequestheaderfieldstoolarge_test.go | ||
errrequesttimeout_test.go | ||
errrequesturitoolong_test.go | ||
errserviceunavailable_test.go | ||
errteapot_test.go | ||
errtooearly_test.go | ||
errtoomanyrequests_test.go | ||
errunauthorized_test.go | ||
errunavailableforlegalreasons_test.go | ||
errunprocessableentity_test.go | ||
errunsupportedmediatype_test.go | ||
errupgraderequired_test.go | ||
errvariantalsonegotiates_test.go | ||
expectationfailed.go | ||
faileddependency.go | ||
forbidden.go | ||
gatewaytimeout.go | ||
gone.go | ||
httpversionnotsupported.go | ||
insufficientstorage.go | ||
internalservererror.go | ||
lengthrequired.go | ||
locked.go | ||
loopdetected.go | ||
methodnotallowed.go | ||
misdirectedrequest.go | ||
networkauthenticationrequired.go | ||
notacceptable.go | ||
notextended.go | ||
notfound.go | ||
notimplemented.go | ||
paymentrequired.go | ||
preconditionfailed.go | ||
preconditionrequired.go | ||
proxyauthrequired.go | ||
requestedrangenotsatisfiable.go | ||
requestentitytoolarge.go | ||
requestheaderfieldstoolarge.go | ||
requesttimeout.go | ||
requesturitoolong.go | ||
servererror.go | ||
serviceunavailable.go | ||
teapot.go | ||
tooearly.go | ||
toomanyrequests.go | ||
unauthorized.go | ||
unavailableforlegalreasons.go | ||
unprocessableentity.go | ||
unsupportedmediatype.go | ||
upgraderequired.go | ||
variantalsonegotiates.go |
README.md
go-errhttp
Package errhttp provides errors and types that make dealing with HTTP response errors easier, for the Go programming language.
Documention
Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-errhttp
Example
Here is an example of wrapping an error:
import "sourcecode.social/reiver/go-errhttp"
// ...
if err := something(); nil != err {
return errhttp.BadRequestWrap(err)
}
// ...
switch err.(type) {
case errhttp.BadRequest:
//@TODO
case errhttp.NotFound:
//@TODO
case errhttp.InternalServerError:
//@TODO
case errhttp.ClientError:
//@TODO
case errhttp.ServerError:
//@TODO
default:
//@TODO
}
Here is an example of using one of the package global variable errors:
import "sourcecode.social/reiver/go-errhttp"
// ...
return errhttp.ErrBadRequest
// ...
switch err.(type) {
case errhttp.BadRequest:
//@TODO
case errhttp.NotFound:
//@TODO
case errhttp.InternalServerError:
//@TODO
case errhttp.ClientError:
//@TODO
case errhttp.ServerError:
//@TODO
default:
//@TODO
}
Here is another example, where it used the .ErrHTTP()
method to get the HTTP response status code:
import "sourcecode.social/reiver/go-errhttp"
// ...
return errhttp.ErrBadRequest
// ...
switch casted := err.(type) {
case errhttp.ClientError:
statuscode := casted.ErrHTTP()
http.Error(responsewriter, http.StatusText(statuscode), statuscode)
return
case errhttp.ServerError:
statuscode := casted.ErrHTTP()
http.Error(responsewriter, http.StatusText(statuscode), statuscode)
return
default:
//@TODO
}