3386b1a18a
fix [EE-6923]
36 lines
781 B
Go
36 lines
781 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
|
"github.com/portainer/portainer/pkg/libhttp/response"
|
|
)
|
|
|
|
func TxResponse[T any](w http.ResponseWriter, r T, err error) *httperror.HandlerError {
|
|
if err != nil {
|
|
var handlerError *httperror.HandlerError
|
|
if errors.As(err, &handlerError) {
|
|
return handlerError
|
|
}
|
|
|
|
return httperror.InternalServerError("Unexpected error", err)
|
|
}
|
|
|
|
return response.JSON(w, r)
|
|
}
|
|
|
|
func TxEmptyResponse(w http.ResponseWriter, err error) *httperror.HandlerError {
|
|
if err != nil {
|
|
var handlerError *httperror.HandlerError
|
|
if errors.As(err, &handlerError) {
|
|
return handlerError
|
|
}
|
|
|
|
return httperror.InternalServerError("Unexpected error", err)
|
|
}
|
|
|
|
return response.Empty(w)
|
|
}
|