Package errhttp provides errors and types that make dealing with HTTP response errors easier, for the Go programming language.
Go to file
Charles Iliya Krempeaux ab4070bfdf made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
LICENSE initial commit 2017-02-06 12:57:57 -08:00
README.md made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
badgateway.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
badrequest.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
clienterror.go client errors 2017-02-06 12:58:13 -08:00
conflict.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
error.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
expectationfailed.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
faileddependency.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
forbidden.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
gatewaytimeout.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
gone.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
httpversionnotsupported.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
insufficientstorage.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
internalservererror.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
lengthrequired.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
locked.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
loopdetected.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
methodnotallowed.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
misdirectedrequest.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
networkauthenticationrequired.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
notacceptable.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
notextended.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
notfound.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
notimplemented.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
paymentrequired.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
preconditionfailed.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
preconditionrequired.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
proxyauthrequired.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
requestedrangenotsatisfiable.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
requestentitytoolarge.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
requestheaderfieldstoolarge.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
requesttimeout.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
requesturitoolong.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
servererror.go client errors 2017-02-06 12:58:13 -08:00
serviceunavailable.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
teapot.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
tooearly.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
toomanyrequests.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
unauthorized.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
unavailableforlegalreasons.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
unprocessableentity.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
unsupportedmediatype.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
upgraderequired.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00
variantalsonegotiates.go made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there. 2023-08-14 06:56:09 -07:00

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

GoDoc

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
	}