github.com/blend/go-sdk@v1.20220411.3/envoyutil/xfcc_errors.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package envoyutil 9 10 import ( 11 "github.com/blend/go-sdk/ex" 12 ) 13 14 // NOTE: Ensure 15 // - `XFCCExtractionError` satisfies `error`. 16 // - `XFCCValidationError` satisfies `error`. 17 // - `XFCCFatalError` satisfies `error`. 18 var ( 19 _ error = (*XFCCExtractionError)(nil) 20 _ error = (*XFCCValidationError)(nil) 21 _ error = (*XFCCFatalError)(nil) 22 ) 23 24 // XFCCExtractionError contains metadata about an XFCC header that could not 25 // be parsed or extracted. This is intended to be used as the body of a 401 26 // Unauthorized response. 27 type XFCCExtractionError struct { 28 // Class can be used to uniquely identify the type of the error. 29 Class ex.Class `json:"class" xml:"class"` 30 // XFCC contains the XFCC header value that could not be parsed or was 31 // invalid in some way. 32 XFCC string `json:"xfcc,omitempty" xml:"xfcc,omitempty"` 33 // Metadata contains extra information relevant to a specific failure. 34 Metadata interface{} `json:"metadata,omitempty" xml:"metadata,omitempty"` 35 } 36 37 // Error satisfies the `error` interface. It is intended to be a unique 38 // identifier for the error. 39 func (xee *XFCCExtractionError) Error() string { 40 return xee.Class.Error() 41 } 42 43 // IsExtractionError is a helper to check if an error is an `*XFCCExtractionError`. 44 func IsExtractionError(err error) bool { 45 _, ok := err.(*XFCCExtractionError) 46 return ok 47 } 48 49 // XFCCValidationError contains metadata about an XFCC header that could not 50 // be parsed or extracted. This is intended to be used as the body of a 401 51 // Unauthorized response. 52 type XFCCValidationError struct { 53 // Class can be used to uniquely identify the type of the error. 54 Class ex.Class `json:"class" xml:"class"` 55 // XFCC contains the XFCC header value that could not be parsed or was 56 // invalid in some way. 57 XFCC string `json:"xfcc,omitempty" xml:"xfcc,omitempty"` 58 // Metadata contains extra information relevant to a specific failure. 59 Metadata interface{} `json:"metadata,omitempty" xml:"metadata,omitempty"` 60 } 61 62 // Error satisfies the `error` interface. It is intended to be a unique 63 // identifier for the error. 64 func (xve *XFCCValidationError) Error() string { 65 return xve.Class.Error() 66 } 67 68 // IsValidationError is a helper to check if an error is an `*XFCCValidationError`. 69 func IsValidationError(err error) bool { 70 _, ok := err.(*XFCCValidationError) 71 return ok 72 } 73 74 // XFCCFatalError contains metadata about an unrecoverable failure when parsing 75 // an XFCC header. A "fatal error" should indicate invalid usage of `envoyutil` 76 // such as providing a `nil` value for a function interface that must be invoked. 77 type XFCCFatalError struct { 78 // Class can be used to uniquely identify the type of the error. 79 Class ex.Class `json:"class" xml:"class"` 80 // XFCC contains the XFCC header value that could not be parsed or was 81 // invalid in some way. 82 XFCC string `json:"xfcc,omitempty" xml:"xfcc,omitempty"` 83 } 84 85 // Error satisfies the `error` interface. It is intended to be a unique 86 // identifier for the error. 87 func (xfe *XFCCFatalError) Error() string { 88 return xfe.Class.Error() 89 } 90 91 // IsFatalError is a helper to check if an error is an `*XFCCFatalError`. 92 func IsFatalError(err error) bool { 93 _, ok := err.(*XFCCFatalError) 94 return ok 95 }