Initial
This commit is contained in:
commit
97dc0a3570
78 files changed
+7054
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"goAuth/internal/auth"
|
||||
"goAuth/internal/invite"
|
||||
"goAuth/internal/jitsi"
|
||||
"goAuth/internal/user"
|
||||
)
|
||||
|
||||
func statusFor(err error) int {
|
||||
switch {
|
||||
case errors.Is(err, user.ErrNotFound),
|
||||
errors.Is(err, auth.ErrNotFound),
|
||||
errors.Is(err, invite.ErrNotFound),
|
||||
errors.Is(err, jitsi.ErrNotFound):
|
||||
return http.StatusNotFound
|
||||
case errors.Is(err, user.ErrInvalidPassword):
|
||||
return http.StatusUnauthorized
|
||||
case errors.Is(err, invite.ErrInvalid),
|
||||
errors.Is(err, user.ErrUnsupportedFormat),
|
||||
errors.Is(err, user.ErrExceedDimensions):
|
||||
return http.StatusBadRequest
|
||||
case errors.Is(err, auth.ErrCanceled):
|
||||
return http.StatusRequestTimeout
|
||||
default:
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) fail(w http.ResponseWriter, err error) {
|
||||
status := statusFor(err)
|
||||
if status == http.StatusInternalServerError {
|
||||
slog.Error("request failed", slog.String("op", "rest.fail"), slog.Any("error", err))
|
||||
writeError(w, status, "internal server error")
|
||||
return
|
||||
}
|
||||
writeError(w, status, err.Error())
|
||||
}
|
||||
Reference in new issue
Block a user