Skip to content
Snippets Groups Projects
Select Git revision
  • 56b30cd912fd70f76baa0c20e4cf2373e4ae1745
  • main default protected
  • trading_hours
  • refactor_trading_hours
  • audit_cleaning_cater_for_non_struct_fields
  • remove-info-logs
  • sl-refactor
  • 18-use-scan-for-param-values
  • 17-order-search-results
  • 4-simplify-framework-2
  • 1-http-error
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
  • v1.278.0
31 results

map_params_test.go

Blame
  • errors.go 2.66 KiB
    package errors
    
    import (
    	"fmt"
    	"github.com/aws/aws-sdk-go/aws/awserr"
    	pkg_errors "github.com/pkg/errors"
    )
    
    // extends default golang error interface
    type ErrorWithCause interface {
    	error
    	Cause() error
    	Code() int
    }
    
    type ErrorWithIs interface {
    	error
    	Is(specificError error) bool
    }
    
    func New(message string) error {
    	err := &CustomError{
    		message: message,
    		caller:  GetCaller(2),
    		cause:   nil,
    	}
    	return err
    }
    
    func Error(message string) error {
    	err := &CustomError{
    		message: message,
    		caller:  GetCaller(2),
    		cause:   nil,
    	}
    	return err
    }
    
    func Errorf(format string, args ...interface{}) error {
    	err := &CustomError{
    		message: fmt.Sprintf(format, args...),
    		caller:  GetCaller(2),
    		cause:   nil,
    	}
    	return err
    }
    
    func Wrapf(err error, format string, args ...interface{}) error {
    	if err == nil {
    		return nil
    	}
    
    	wrappedErr := &CustomError{
    		message: fmt.Sprintf(format, args...),
    		caller:  GetCaller(2),
    		cause:   err,
    	}
    
    	return wrappedErr
    }
    
    func Wrap(err error, msg string) error {
    	if err == nil {
    		return nil
    	}
    
    	wrappedErr := &CustomError{
    		message: msg,
    		caller:  GetCaller(2),
    		cause:   err,
    	}
    
    	return wrappedErr
    }
    
    func HTTP(code int, err error, format string, args ...interface{}) error {
    	wrappedErr := &CustomError{
    		code:    code,
    		message: fmt.Sprintf(format, args...),
    		caller:  GetCaller(2),
    		cause:   err,
    	}
    
    	return wrappedErr
    }
    
    func HTTPWithMsg(code int, format string, args ...interface{}) error {
    	errorString := fmt.Sprintf(format, args...)
    
    	wrappedErr := &CustomError{
    		code:    code,
    		message: errorString,
    		caller:  GetCaller(2),
    		cause:   Error(errorString),
    	}
    
    	return wrappedErr
    }
    
    func HTTPCodeOnly(code int) error {
    	return HTTP(code, nil, "")
    }
    
    func HTTPWithError(code int, err error) error {
    	var errorMessage string
    	// This check is here just as a failsafe to seg faults, if err is nil then just return assign an empty string as message.
    	if err != nil {
    		errorMessage = err.Error()
    	}
    
    	wrappedErr := &CustomError{
    		code:    code,
    		message: errorMessage,
    		caller:  GetCaller(2),
    		cause:   err,
    	}
    
    	return wrappedErr
    }
    
    func AWSErrorExceptionCode(err error) string {
    	if err == nil {
    		return ""
    	}
    
    	if awsError, ok := err.(awserr.Error); ok {
    		return awsError.Code()
    	}
    	return ""
    }
    
    func AWSErrorWithoutExceptionCode(err error) error {
    	if err == nil {
    		return nil
    	}
    
    	if awsError, ok := err.(awserr.Error); ok {
    		return Error(awsError.Message())
    	}
    	return err
    }
    
    type Description struct {
    	Message string       `json:"error"`
    	Source  *CallerInfo  `json:"source,omitempty"`
    	Cause   *Description `json:"cause,omitempty"`
    }
    
    // from github.com/pkg/errors:
    type stackTracer interface {
    	StackTrace() pkg_errors.StackTrace
    }