s3tables: fix double-write issue in handleListTables
Remove premature HTTP error writes from within WithFilerClient closure to prevent duplicate status code responses. Error handling is now consistently performed at the top level using isAuthError.
This commit is contained in:
@@ -309,7 +309,6 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if accountID := h.getAccountID(r); accountID != nsMeta.OwnerAccountID {
|
if accountID := h.getAccountID(r); accountID != nsMeta.OwnerAccountID {
|
||||||
h.writeError(w, http.StatusNotFound, ErrCodeNoSuchNamespace, "namespace not found")
|
|
||||||
return ErrAccessDenied
|
return ErrAccessDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +325,6 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if accountID := h.getAccountID(r); accountID != bucketMeta.OwnerAccountID {
|
if accountID := h.getAccountID(r); accountID != bucketMeta.OwnerAccountID {
|
||||||
h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, "bucket not found")
|
|
||||||
return ErrAccessDenied
|
return ErrAccessDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,16 +338,13 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques
|
|||||||
// If the bucket or namespace directory is not found, return an empty result
|
// If the bucket or namespace directory is not found, return an empty result
|
||||||
tables = []TableSummary{}
|
tables = []TableSummary{}
|
||||||
paginationToken = ""
|
paginationToken = ""
|
||||||
} else {
|
} else if isAuthError(err) {
|
||||||
var authErr *AuthError
|
h.writeError(w, http.StatusForbidden, ErrCodeAccessDenied, "Access Denied")
|
||||||
if errors.As(err, &authErr) {
|
|
||||||
h.writeError(w, http.StatusForbidden, ErrCodeAccessDenied, err.Error())
|
|
||||||
} else {
|
} else {
|
||||||
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to list tables: %v", err))
|
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to list tables: %v", err))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
resp := &ListTablesResponse{
|
resp := &ListTablesResponse{
|
||||||
Tables: tables,
|
Tables: tables,
|
||||||
|
|||||||
Reference in New Issue
Block a user