s3tables: improve pagination robustness and error handling in table listing handlers
This commit is contained in:
@@ -337,7 +337,9 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, filer_pb.ErrNotFound) {
|
if errors.Is(err, filer_pb.ErrNotFound) {
|
||||||
h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, "resource not found")
|
// If the bucket or namespace directory is not found, return an empty result
|
||||||
|
tables = []TableSummary{}
|
||||||
|
paginationToken = ""
|
||||||
} else {
|
} else {
|
||||||
var authErr *AuthError
|
var authErr *AuthError
|
||||||
if errors.As(err, &authErr) {
|
if errors.As(err, &authErr) {
|
||||||
@@ -345,8 +347,8 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques
|
|||||||
} 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{
|
||||||
@@ -450,6 +452,9 @@ func (h *S3TablesHandler) listTablesWithClient(r *http.Request, client filer_pb.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(tables) < maxTables {
|
||||||
|
lastFileName = ""
|
||||||
|
}
|
||||||
return tables, lastFileName, nil
|
return tables, lastFileName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,7 +481,7 @@ func (h *S3TablesHandler) listTablesInAllNamespaces(r *http.Request, client file
|
|||||||
Directory: bucketPath,
|
Directory: bucketPath,
|
||||||
Limit: 100,
|
Limit: 100,
|
||||||
StartFromFileName: lastNamespace,
|
StartFromFileName: lastNamespace,
|
||||||
InclusiveStartFrom: lastNamespace == continuationNamespace && continuationNamespace != "" || lastNamespace == "",
|
InclusiveStartFrom: (lastNamespace == continuationNamespace && startTableName != "") || (lastNamespace == "" && continuationNamespace == ""),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user