@@ -28,8 +28,12 @@ import {
2828 makeApi ,
2929 LabelsColorMapSource ,
3030 getClientErrorObject ,
31+ ErrorTypeEnum ,
32+ SupersetError ,
33+ SupersetApiError ,
3134} from '@superset-ui/core' ;
3235import { Loading } from '@superset-ui/core/components' ;
36+ import { OAuth2RedirectMessage } from 'src/components/ErrorMessage' ;
3337import { addDangerToast } from 'src/components/MessageToasts/actions' ;
3438import { getUrlParam } from 'src/utils/urlUtils' ;
3539import { URL_PARAMS } from 'src/constants' ;
@@ -144,6 +148,8 @@ const getDashboardContextFormData = (search: string) => {
144148
145149export default function ExplorePage ( ) {
146150 const [ isLoaded , setIsLoaded ] = useState ( false ) ;
151+ const [ authenticationError , setAuthenticationError ] =
152+ useState < SupersetError < { url : string ; tab_id : string } > > ( ) ;
147153 const fetchGeneration = useRef ( 0 ) ;
148154 const abortControllerRef = useRef < AbortController | null > ( null ) ;
149155 const dispatch = useDispatch ( ) ;
@@ -155,6 +161,7 @@ export default function ExplorePage() {
155161 loc : { search : string ; pathname : string } ,
156162 saveAction ?: SaveActionType | null ,
157163 ) => {
164+ setAuthenticationError ( undefined ) ;
158165 // Abort any in-flight request before starting a new one
159166 abortControllerRef . current ?. abort ( ) ;
160167 const controller = new AbortController ( ) ;
@@ -231,6 +238,33 @@ export default function ExplorePage() {
231238 if ( ! err ) {
232239 return Promise . resolve ( ) ;
233240 }
241+ const oauthError : SupersetError | undefined =
242+ clientError ?. errors ?. find (
243+ error => error . error_type === ErrorTypeEnum . OAUTH2_REDIRECT ,
244+ ) ??
245+ ( err instanceof SupersetApiError &&
246+ String ( err . errorType ) === ErrorTypeEnum . OAUTH2_REDIRECT
247+ ? {
248+ error_type : ErrorTypeEnum . OAUTH2_REDIRECT ,
249+ level : 'warning' ,
250+ message : err . message ,
251+ extra : err . extra ,
252+ }
253+ : undefined ) ;
254+ if (
255+ oauthError &&
256+ typeof oauthError . extra ?. url === 'string' &&
257+ typeof oauthError . extra ?. tab_id === 'string'
258+ ) {
259+ setAuthenticationError ( {
260+ ...oauthError ,
261+ extra : {
262+ url : oauthError . extra . url ,
263+ tab_id : oauthError . extra . tab_id ,
264+ } ,
265+ } ) ;
266+ return Promise . resolve ( ) ;
267+ }
234268 const errorMesage =
235269 clientError ?. message ||
236270 clientError ?. error ||
@@ -379,5 +413,17 @@ export default function ExplorePage() {
379413 if ( ! isLoaded ) {
380414 return < Loading /> ;
381415 }
416+ if ( authenticationError ) {
417+ return (
418+ < OAuth2RedirectMessage
419+ error = { authenticationError }
420+ source = "explore"
421+ errorMitigationFunction = { ( ) => {
422+ setIsLoaded ( false ) ;
423+ loadExploreData ( history . location ) ;
424+ } }
425+ />
426+ ) ;
427+ }
382428 return < ExploreViewContainer /> ;
383429}
0 commit comments