errors.go 612 B

123456789101112131415161718192021222324252627282930313233
  1. package plugins
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. type statusError struct {
  7. status int
  8. method string
  9. err string
  10. }
  11. // Error returns a formated string for this error type
  12. func (e *statusError) Error() string {
  13. return fmt.Sprintf("%s: %v", e.method, e.err)
  14. }
  15. // IsNotFound indicates if the passed in error is from an http.StatusNotFound from the plugin
  16. func IsNotFound(err error) bool {
  17. return isStatusError(err, http.StatusNotFound)
  18. }
  19. func isStatusError(err error, status int) bool {
  20. if err == nil {
  21. return false
  22. }
  23. e, ok := err.(*statusError)
  24. if !ok {
  25. return false
  26. }
  27. return e.status == status
  28. }