@@ -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