...

Source file src/edge-infra.dev/pkg/edge/iam/apperror/app.go

Documentation: edge-infra.dev/pkg/edge/iam/apperror

     1  package apperror
     2  
     3  import "fmt"
     4  
     5  // AppError should be created by the inner packages.
     6  // Later, the handler layer can wrap them into errors like StatusError, AbortError, JSONError, RedirectError.
     7  type AppError struct {
     8  	code    string
     9  	message string
    10  	err     error
    11  }
    12  
    13  // New creates an AppError
    14  func New(err error, code string, msg string) *AppError {
    15  	return &AppError{
    16  		code:    code,
    17  		message: msg,
    18  		err:     err,
    19  	}
    20  }
    21  
    22  func (e AppError) Error() string {
    23  	return fmt.Sprintf("%s <%s>. %v", e.message, e.code, e.err.Error())
    24  }
    25  
    26  func (e AppError) Unwrap() error {
    27  	return e.err
    28  }
    29  
    30  func (e AppError) ErrorCode() string {
    31  	return e.code
    32  }
    33  

View as plain text