openmeter / ingest /httpdriver /errors.go
Leon4gr45's picture
Upload folder using huggingface_hub (part 5)
cee2387 verified
Raw
History Blame Contribute Delete
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)
}
}