Download ingest/httpdriver/errors.go from Leon4gr45/openmeter: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/ingest/httpdriver/errors.go
- Command line
-
hf download hf://spaces/Leon4gr45/openmeter/ingest/httpdriver/errors.go
-
curl -L -o errors.go https://huggingface.co/spaces/Leon4gr45/openmeter/resolve/main/ingest/httpdriver/errors.go
1.22 kB
| package httpdriver | |
| import ( | |
| "context" | |
| "net/http" | |
| "github.com/openmeterio/openmeter/pkg/framework/commonhttp" | |
| "github.com/openmeterio/openmeter/pkg/framework/transport/httptransport/encoder" | |
| ) | |
| type ErrorInvalidContentType struct { | |
| ContentType string | |
| } | |
| func (e ErrorInvalidContentType) Error() string { | |
| // return "invalid content type" | |
| return "invalid content type: " + e.ContentType | |
| } | |
| func (e ErrorInvalidContentType) Message() string { | |
| return "invalid content type: " + e.ContentType | |
| } | |
| func (e ErrorInvalidContentType) Details() map[string]any { | |
| return map[string]any{ | |
| "contentType": e.ContentType, | |
| } | |
| } | |
| type ErrorInvalidEvent struct { | |
| Err error | |
| } | |
| func (e ErrorInvalidEvent) Error() string { | |
| // return "invalid event" | |
| return "invalid event: " + e.Err.Error() | |
| } | |
| func (e ErrorInvalidEvent) Message() string { | |
| return "invalid event: " + e.Err.Error() | |
| } | |
| func errorEncoder() encoder.ErrorEncoder { | |
| return func(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool { | |
| return commonhttp.HandleErrorIfTypeMatches[ErrorInvalidContentType](ctx, http.StatusBadRequest, err, w) || | |
| commonhttp.HandleErrorIfTypeMatches[ErrorInvalidEvent](ctx, http.StatusBadRequest, err, w) | |
| } | |
| } | |