prysm-pulse/beacon-chain/rpc/core/errors.go

55 lines
971 B
Go
Raw Normal View History

package core
import (
"net/http"
"google.golang.org/grpc/codes"
)
type ErrorReason uint8
const (
Internal = iota
Unavailable
BadRequest
Beacon API: update Deneb endpoints after removing blob signing (#13235) * making needed changes to beacon API based on removal of blobsidecar from block contents * fixing tests and reverting some changes to be addressed later * fixing generated code from protos * gaz * fixing get blob handler and adding blob storage to the blob service * updating unit tests * WIP * wip tests * got tests passing but needs cleanup * removing gomod and gosum changes * fixing more tests * fixing more tests * fixing more tests * gaz * moving some proto types around * removing unneeded unit test * fixing proposer paths * adding more tests * fixing more tests * improving more unit tests * updating one blob only unit test * changing arguments of buildBlobSidecar * reverting a change based on feedback * terence's review items * fixing test based on new develop changes * radek's comments * addressed more comments from radek * adding in blobs to test data * fixing casing in test * removing extra line * fixing issue from bad merge * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/blob/handlers.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * moving core getblob business logic to blocker based on radek's comment * fixing mock blocker * gaz --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2023-12-07 17:37:11 +00:00
NotFound
// Add more errors as needed
)
type RpcError struct {
Err error
Reason ErrorReason
}
func ErrorReasonToGRPC(reason ErrorReason) codes.Code {
switch reason {
case Internal:
return codes.Internal
case Unavailable:
return codes.Unavailable
case BadRequest:
return codes.InvalidArgument
Beacon API: update Deneb endpoints after removing blob signing (#13235) * making needed changes to beacon API based on removal of blobsidecar from block contents * fixing tests and reverting some changes to be addressed later * fixing generated code from protos * gaz * fixing get blob handler and adding blob storage to the blob service * updating unit tests * WIP * wip tests * got tests passing but needs cleanup * removing gomod and gosum changes * fixing more tests * fixing more tests * fixing more tests * gaz * moving some proto types around * removing unneeded unit test * fixing proposer paths * adding more tests * fixing more tests * improving more unit tests * updating one blob only unit test * changing arguments of buildBlobSidecar * reverting a change based on feedback * terence's review items * fixing test based on new develop changes * radek's comments * addressed more comments from radek * adding in blobs to test data * fixing casing in test * removing extra line * fixing issue from bad merge * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/blob/handlers.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * moving core getblob business logic to blocker based on radek's comment * fixing mock blocker * gaz --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2023-12-07 17:37:11 +00:00
case NotFound:
return codes.NotFound
// Add more cases for other error reasons as needed
default:
return codes.Internal
}
}
func ErrorReasonToHTTP(reason ErrorReason) int {
switch reason {
case Internal:
return http.StatusInternalServerError
case Unavailable:
return http.StatusServiceUnavailable
case BadRequest:
return http.StatusBadRequest
Beacon API: update Deneb endpoints after removing blob signing (#13235) * making needed changes to beacon API based on removal of blobsidecar from block contents * fixing tests and reverting some changes to be addressed later * fixing generated code from protos * gaz * fixing get blob handler and adding blob storage to the blob service * updating unit tests * WIP * wip tests * got tests passing but needs cleanup * removing gomod and gosum changes * fixing more tests * fixing more tests * fixing more tests * gaz * moving some proto types around * removing unneeded unit test * fixing proposer paths * adding more tests * fixing more tests * improving more unit tests * updating one blob only unit test * changing arguments of buildBlobSidecar * reverting a change based on feedback * terence's review items * fixing test based on new develop changes * radek's comments * addressed more comments from radek * adding in blobs to test data * fixing casing in test * removing extra line * fixing issue from bad merge * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/beacon/handlers_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/rpc/eth/blob/handlers.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * moving core getblob business logic to blocker based on radek's comment * fixing mock blocker * gaz --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2023-12-07 17:37:11 +00:00
case NotFound:
return http.StatusNotFound
// Add more cases for other error reasons as needed
default:
return http.StatusInternalServerError
}
}