功能修改

This commit is contained in:
npc0-hue
2026-07-20 16:42:33 +08:00
parent 48b8ad8d6c
commit a0e69417db
224 changed files with 22015 additions and 884 deletions
+8
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"browser.local/platform/dto"
"browser.local/platform/repo"
@@ -60,11 +61,18 @@ func writeMethodNotAllowed(w http.ResponseWriter, allow string) {
func writeServiceError(w http.ResponseWriter, err error) {
var validationErr validator.ValidationError
var forbiddenErr service.ForbiddenError
switch {
case errors.As(err, &validationErr):
writeAPIError(w, http.StatusBadRequest, errorCodeValidation, "validation failed", validationErr.Violations)
case errors.Is(err, service.ErrUnauthorized):
writeAPIError(w, http.StatusUnauthorized, errorCodeUnauthorized, "authentication required", nil)
case errors.As(err, &forbiddenErr):
message := strings.TrimSpace(forbiddenErr.Reason)
if message == "" {
message = "account is not allowed to access this resource"
}
writeAPIError(w, http.StatusForbidden, errorCodeForbidden, message, nil)
case errors.Is(err, service.ErrForbidden):
writeAPIError(w, http.StatusForbidden, errorCodeForbidden, "account is not allowed to access this resource", nil)
case errors.Is(err, repo.ErrDuplicate):