mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
3a09405bb7
* HTTP Beacon API: `/eth/v1/validator/contribution_and_proofs` * add comment to invalid test case * fix validation and test * review * in progress * implementation * remove test file * remove duplicate * tests * review * test fixes --------- Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
29 lines
878 B
Go
29 lines
878 B
Go
package shared
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// DecodeError represents an error resulting from trying to decode an HTTP request.
|
|
// It tracks the full field name for which decoding failed.
|
|
type DecodeError struct {
|
|
path []string
|
|
err error
|
|
}
|
|
|
|
// NewDecodeError wraps an error (either the initial decoding error or another DecodeError).
|
|
// The current field that failed decoding must be passed in.
|
|
func NewDecodeError(err error, field string) *DecodeError {
|
|
de, ok := err.(*DecodeError)
|
|
if ok {
|
|
return &DecodeError{path: append([]string{field}, de.path...), err: de.err}
|
|
}
|
|
return &DecodeError{path: []string{field}, err: err}
|
|
}
|
|
|
|
// Error returns the formatted error message which contains the full field name and the actual decoding error.
|
|
func (e *DecodeError) Error() string {
|
|
return fmt.Sprintf("could not decode %s: %s", strings.Join(e.path, "."), e.err.Error())
|
|
}
|