github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/internal/http/error.go (about)

     1  package http
     2  
     3  import "fmt"
     4  
     5  // NotImplementedErr Error
     6  type NotImplementedErr struct {
     7  }
     8  
     9  // Error method - satisfying error interface
    10  func (err *NotImplementedErr) Error() string {
    11  	return fmt.Sprintf("Not Implemented Yet")
    12  }
    13  
    14  // NewNotImplementedErr - return a new instance of NotImplementedErr
    15  func NewNotImplementedErr() error {
    16  	return &NotImplementedErr{}
    17  }
    18  
    19  // CreateServerErr Error
    20  type CreateServerErr struct {
    21  	Err error
    22  }
    23  
    24  // Error method - satisfying error interface
    25  func (err *CreateServerErr) Error() string {
    26  	return fmt.Sprintf("Create a new server encounterred an error: %v", err.Err)
    27  }
    28  
    29  // NewCreateServerErr - return a new instance of CreateServerErr
    30  func NewCreateServerErr(err error) error {
    31  	return &CreateServerErr{Err: err}
    32  }
    33  
    34  // StartServerErr Error
    35  type StartServerErr struct {
    36  	Err           error
    37  	ListenAddress string
    38  }
    39  
    40  // Error method - satisfying error interface
    41  func (err *StartServerErr) Error() string {
    42  	return fmt.Sprintf("Starting server on `%v` encounterred an error: %v", err.ListenAddress, err.Err)
    43  }
    44  
    45  // NewStartServerErr - return a new instance of StartServerErr
    46  func NewStartServerErr(addr string, err error) error {
    47  	return &StartServerErr{Err: err, ListenAddress: addr}
    48  }
    49  
    50  // ShutdownServerErr Error
    51  type ShutdownServerErr struct {
    52  	Err error
    53  }
    54  
    55  // Error method - satisfying error interface
    56  func (err *ShutdownServerErr) Error() string {
    57  	return fmt.Sprintf("Shutting down server encounterred an error: %v", err.Err)
    58  }
    59  
    60  // NewShutdownServerErr - return a new instance of StartServerErr
    61  func NewShutdownServerErr(err error) error {
    62  	return &ShutdownServerErr{Err: err}
    63  }
    64  
    65  // NotSupportedHttpMethodErr Error
    66  type NotSupportedHttpMethodErr struct {
    67  	method string
    68  }
    69  
    70  // Error method - satisfying error interface
    71  func (err *NotSupportedHttpMethodErr) Error() string {
    72  	return fmt.Sprintf("This method '%v' is not supported", err.method)
    73  }
    74  
    75  // NewNotSupportedHttpMethodErr - return a new instance of NotSupportedHttpMethodErr
    76  func NewNotSupportedHttpMethodErr(method string) error {
    77  	return &NotSupportedHttpMethodErr{method: method}
    78  }
    79  
    80  // AddRouteToNilServerErr Error
    81  type AddRouteToNilServerErr struct {
    82  	route string
    83  }
    84  
    85  // Error method - satisfying error interface
    86  func (err *AddRouteToNilServerErr) Error() string {
    87  	return fmt.Sprintf("There is no server to add route: %v", err.route)
    88  }
    89  
    90  // NewAddRouteToNilServerErr - return a new instance of AddRouteToNilServerErr
    91  func NewAddRouteToNilServerErr(route string) error {
    92  	return &AddRouteToNilServerErr{route: route}
    93  }
    94  
    95  // GetRouteByNameErr Error
    96  type GetRouteByNameErr struct {
    97  	name string
    98  }
    99  
   100  // Error method - satisfying error interface
   101  func (err *GetRouteByNameErr) Error() string {
   102  	return fmt.Sprintf("There is no route be the name: %v", err.name)
   103  }
   104  
   105  // NewGetRouteByNameErr - return a new instance of GetRouteByNameErr
   106  func NewGetRouteByNameErr(name string) error {
   107  	return &GetRouteByNameErr{name: name}
   108  }
   109  
   110  // FromNilServerErr Error
   111  type FromNilServerErr struct {
   112  }
   113  
   114  // Error method - satisfying error interface
   115  func (err *FromNilServerErr) Error() string {
   116  	return fmt.Sprintf("There is no server to operate")
   117  }
   118  
   119  // NewFromNilServerErr - return a new instance of FromNilServerErr
   120  func NewFromNilServerErr() error {
   121  	return &FromNilServerErr{}
   122  }
   123  
   124  // FromMultipleServerErr Error
   125  type FromMultipleServerErr struct {
   126  }
   127  
   128  // Error method - satisfying error interface
   129  func (err *FromMultipleServerErr) Error() string {
   130  	return fmt.Sprintf("There are more than one server to operate")
   131  }
   132  
   133  // NewFromMultipleServerErr - return a new instance of FromMultipleServerErr
   134  func NewFromMultipleServerErr() error {
   135  	return &FromMultipleServerErr{}
   136  }
   137  
   138  // GroupRouteNotExistErr Error
   139  type GroupRouteNotExistErr struct {
   140  	name string
   141  }
   142  
   143  // Error method - satisfying error interface
   144  func (err *GroupRouteNotExistErr) Error() string {
   145  	return fmt.Sprintf("There is no group route be the name: %v", err.name)
   146  }
   147  
   148  // NewGroupRouteNotExistErr - return a new instance of GroupRouteNotExistErr
   149  func NewGroupRouteNotExistErr(name string) error {
   150  	return &GroupRouteNotExistErr{name: name}
   151  }
   152  
   153  // AddGroupToNilServerErr Error
   154  type AddGroupToNilServerErr struct {
   155  	groupName string
   156  }
   157  
   158  // Error method - satisfying error interface
   159  func (err *AddGroupToNilServerErr) Error() string {
   160  	return fmt.Sprintf("There is no server to add route: %v", err.groupName)
   161  }
   162  
   163  // NewAddGroupToNilServerErr - return a new instance of AddGroupToNilServerErr
   164  func NewAddGroupToNilServerErr(name string) error {
   165  	return &AddGroupToNilServerErr{groupName: name}
   166  }
   167  
   168  // AttachErrorHandlerToNilServerErr Error
   169  type AttachErrorHandlerToNilServerErr struct {
   170  	serverNames []string
   171  }
   172  
   173  // Error method - satisfying error interface
   174  func (err *AttachErrorHandlerToNilServerErr) Error() string {
   175  	return fmt.Sprintf("There is no server to attach error handler: %v", err.serverNames)
   176  }
   177  
   178  // NewAttachErrorHandlerToNilServerErr - return a new instance of AttachErrorHandlerToNilServerErr
   179  func NewAttachErrorHandlerToNilServerErr(serverNames ...string) error {
   180  	return &AttachErrorHandlerToNilServerErr{serverNames: serverNames}
   181  }