service_error.go 980 B

1234567891011121314151617181920212223242526272829303132
  1. package restful
  2. // Copyright 2013 Ernest Micklei. All rights reserved.
  3. // Use of this source code is governed by a license
  4. // that can be found in the LICENSE file.
  5. import (
  6. "fmt"
  7. "net/http"
  8. )
  9. // ServiceError is a transport object to pass information about a non-Http error occurred in a WebService while processing a request.
  10. type ServiceError struct {
  11. Code int
  12. Message string
  13. Header http.Header
  14. }
  15. // NewError returns a ServiceError using the code and reason
  16. func NewError(code int, message string) ServiceError {
  17. return ServiceError{Code: code, Message: message}
  18. }
  19. // NewErrorWithHeader returns a ServiceError using the code, reason and header
  20. func NewErrorWithHeader(code int, message string, header http.Header) ServiceError {
  21. return ServiceError{Code: code, Message: message, Header: header}
  22. }
  23. // Error returns a text representation of the service error
  24. func (s ServiceError) Error() string {
  25. return fmt.Sprintf("[ServiceError:%v] %v", s.Code, s.Message)
  26. }