Download api/v3/apierrors/encoder.go from Leon4gr45/openmeter: direct link, hf CLI and curl.
- Browser
- Download file 951 Bytes
-
https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/api/v3/apierrors/encoder.go
- Command line
-
hf download hf://spaces/Leon4gr45/openmeter/api/v3/apierrors/encoder.go
-
curl -L -o encoder.go https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/api/v3/apierrors/encoder.go
951 Bytes
| package apierrors | |
| import ( | |
| "context" | |
| "net/http" | |
| "github.com/samber/lo" | |
| "github.com/openmeterio/openmeter/openmeter/meter" | |
| "github.com/openmeterio/openmeter/openmeter/productcatalog/feature" | |
| "github.com/openmeterio/openmeter/pkg/framework/commonhttp" | |
| "github.com/openmeterio/openmeter/pkg/framework/transport/httptransport/encoder" | |
| ) | |
| // GenericErrorEncoder is an error encoder that encodes the error as a generic error. | |
| func GenericErrorEncoder() encoder.ErrorEncoder { | |
| return func(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool { | |
| if err, ok := lo.ErrorsAs[*BaseAPIError](err); ok { | |
| err.HandleAPIError(w, r) | |
| return true | |
| } | |
| return commonhttp.HandleErrorIfTypeMatches[*feature.FeatureNotFoundError](ctx, http.StatusNotFound, err, w) || | |
| commonhttp.HandleErrorIfTypeMatches[*meter.MeterNotFoundError](ctx, http.StatusNotFound, err, w) || | |
| commonhttp.HandleIssueIfHTTPStatusKnown(ctx, err, w) | |
| } | |
| } | |