Skip to content

Commit 1a4f23b

Browse files
authored
Core: Fix REST catalog handling when the service has no view support (apache#9853)
* Core: Fix REST catalog handling when the service has no view support. * Fix error message. * Improve the error message.
1 parent f9ad8f3 commit 1a4f23b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,12 +1058,22 @@ public List<TableIdentifier> listViews(SessionContext context, Namespace namespa
10581058
public View loadView(SessionContext context, TableIdentifier identifier) {
10591059
checkViewIdentifierIsValid(identifier);
10601060

1061-
LoadViewResponse response =
1062-
client.get(
1063-
paths.view(identifier),
1064-
LoadViewResponse.class,
1065-
headers(context),
1066-
ErrorHandlers.viewErrorHandler());
1061+
LoadViewResponse response;
1062+
try {
1063+
response =
1064+
client.get(
1065+
paths.view(identifier),
1066+
LoadViewResponse.class,
1067+
headers(context),
1068+
ErrorHandlers.viewErrorHandler());
1069+
} catch (UnsupportedOperationException | RESTException e) {
1070+
// Normally, copying an exception message is a bad practice but engines may show just the
1071+
// message and suppress the exception cause when the view does not exist. Since 401 and 403
1072+
// responses can trigger this case, including the message increases the chances that the "Not
1073+
// authorized" or "Forbidden" message is preserved and shown.
1074+
throw new NoSuchViewException(
1075+
e, "Unable to load view %s.%s: %s", name(), identifier, e.getMessage());
1076+
}
10671077

10681078
AuthSession session = tableSession(response.config(), session(context));
10691079
ViewMetadata metadata = response.metadata();

0 commit comments

Comments
 (0)