github.com/xmidt-org/webpa-common@v1.11.9/convey/error.go (about)

     1  package convey
     2  
     3  type Compliance int
     4  
     5  const (
     6  	Full Compliance = iota
     7  	Missing
     8  	Invalid
     9  
    10  	MissingFields
    11  )
    12  
    13  func (c Compliance) String() string {
    14  	switch c {
    15  	case Full:
    16  		return "full"
    17  	case Missing:
    18  		return "missing-convey"
    19  	case Invalid:
    20  		return "invalid-convey"
    21  	case MissingFields:
    22  		return "convey-missing-fields"
    23  	default:
    24  		return "*invalid*"
    25  	}
    26  }
    27  
    28  type Comply interface {
    29  	Compliance() Compliance
    30  }
    31  
    32  // GetCompliance examines an error for Compliance information.
    33  //   If err is nil, Full is returned
    34  //   If err implements Comply, the result of the Compliance method is returne
    35  //   Otherwise, Invalid is returned
    36  func GetCompliance(err error) Compliance {
    37  	if err == nil {
    38  		return Full
    39  	}
    40  
    41  	if c, ok := err.(Comply); ok {
    42  		return c.Compliance()
    43  	}
    44  
    45  	return Invalid
    46  }
    47  
    48  type Error struct {
    49  	Err error
    50  	C   Compliance
    51  }
    52  
    53  func (e Error) Error() string {
    54  	return e.Err.Error()
    55  }
    56  
    57  func (e Error) Compliance() Compliance {
    58  	return e.C
    59  }