service_error.go 708 B

1234567891011121314151617181920212223
  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 "fmt"
  6. // ServiceError is a transport object to pass information about a non-Http error occurred in a WebService while processing a request.
  7. type ServiceError struct {
  8. Code int
  9. Message string
  10. }
  11. // NewError returns a ServiceError using the code and reason
  12. func NewError(code int, message string) ServiceError {
  13. return ServiceError{Code: code, Message: message}
  14. }
  15. // Error returns a text representation of the service error
  16. func (s ServiceError) Error() string {
  17. return fmt.Sprintf("[ServiceError:%v] %v", s.Code, s.Message)
  18. }