mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-09-30 03:51:43 +02:00
* Switch from golang.org/x/net/websocket to nhooyr.io/websocket * Do not attach errors that we can handle to the Gin's context * Add missing newline to "no credentials specified or found, ..." message * Fix potential NPE in ChooseUsernameAndPassword() * Fix type in PortForward() error message in "orchard ssh vm" * Fix potential NPE in Connections() * Use header.Set() for consistency's sake for Authorization header
32 lines
526 B
Go
32 lines
526 B
Go
package responder
|
|
|
|
import (
|
|
"errors"
|
|
storepkg "github.com/cirruslabs/orchard/internal/controller/store"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
type ErrorResponder struct {
|
|
err error
|
|
Responder
|
|
}
|
|
|
|
func Error(err error) Responder {
|
|
return &ErrorResponder{
|
|
err: err,
|
|
}
|
|
}
|
|
|
|
func (responder *ErrorResponder) Respond(c *gin.Context) {
|
|
var code = http.StatusInternalServerError
|
|
|
|
if errors.Is(responder.err, storepkg.ErrNotFound) {
|
|
code = http.StatusNotFound
|
|
} else {
|
|
_ = c.Error(responder.err)
|
|
}
|
|
|
|
c.Status(code)
|
|
}
|