...

Source file src/github.com/emicklei/go-restful/v3/service_error.go

Documentation: github.com/emicklei/go-restful/v3

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

View as plain text