2023-05-30 18:33:22 +00:00
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2023-09-01 22:27:02 +00:00
|
|
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
2023-05-30 18:33:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TxResponse(err error, validResponse func() *httperror.HandlerError) *httperror.HandlerError {
|
|
|
|
if err != nil {
|
|
|
|
var handlerError *httperror.HandlerError
|
|
|
|
if errors.As(err, &handlerError) {
|
|
|
|
return handlerError
|
|
|
|
}
|
|
|
|
|
|
|
|
return httperror.InternalServerError("Unexpected error", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return validResponse()
|
|
|
|
}
|