Repository: microsoftgraph/microsoft-graph-explorer-v4 (ts)

Issue:
API call results in a hung UI
**Describe the bug**
Made a call and the Response Preview and Run Query UI elements are not updated. The Run Query element continues with the in progress circle, the Response Preview doesn't show the response. But if I look in History, the response is there.

**To Reproduce**
Steps to reproduce the behavior:
1. Call https://graph.microsoft.com/v1.0/deviceManagement/managedDevices
2. Observe the Run Query and Response Preview elements are not updated.
3. Go to History tab and see the result. 

**Expected behavior**
Run Query UI is updated and the response is shown in Response Preview.

**Screenshots**
![image](https://user-images.githubusercontent.com/8527305/229632771-a979bec2-c48e-4994-8096-7b5adf18bb2f.png)

**Desktop (please complete the following information):**
 - OS: [e.g. iOS]
 - Browser [e.g. chrome, safari]
 - Version [e.g. 22]

**Smartphone (please complete the following information):**
 - Device: Desktop
 - OS: Windows 11
 - Browser Edge
 - Version  111.0.1661.54

**Additional context**
Browser is telling me to update. Will try.... same issue


Pull request description:
Fix: Run query loop
## Overview
Fixes #2474 

### Demo
![image](https://user-images.githubusercontent.com/45680252/229801533-6276f4d8-9610-4271-9a01-e20f13188ee5.png)


### Notes

Optional. Ancillary topics, caveats, alternative strategies that didn't work out, anything else.

## Testing Instructions

* How to test this PR
Sign in with a Microsoft account with permission restrictions
Run Query that might return a 401 e.g: https://graph.microsoft.com/v1.0/deviceAppManagement/managedAppPolicies
Notice fix

Patch:
diff --git a/src/app/services/actions/query-action-creators.spec.ts b/src/app/services/actions/query-action-creators.spec.ts
index 1b5fd01a..7f1cca25 100644
--- a/src/app/services/actions/query-action-creators.spec.ts
+++ b/src/app/services/actions/query-action-creators.spec.ts
@@ -108,4 +108,30 @@ describe('Query action creators', () => {
       })
       .catch((e: Error) => { throw e });
   });
+
+  it('should dispatch query status when a 401 is received', () => {
+    const sampleUrl = 'https://graph.microsoft.com/v1.0/me';
+
+    const store = mockStore({ graphResponse: '' });
+    const query = { sampleUrl }
+    const mockFetch = jest.fn().mockImplementation(() => {
+      return Promise.resolve({
+        ok: false,
+        status: 401,
+        body: {},
+        headers: [{ 'content-type': 'application-json' }]
+      })
+    });
+
+    window.fetch = mockFetch;
+
+    // @ts-ignore
+    return store.dispatch(runQuery(query))
+      .then((response) => {
+        expect(response.type).toBe('QUERY_GRAPH_STATUS');
+        expect(response.response.ok).toBe(false);
+      })
+      .catch((e: Error) => { throw e });
+
+  })
 });
diff --git a/src/app/services/actions/query-action-creators.ts b/src/app/services/actions/query-action-creators.ts
index d8892fac..1701be8d 100644
--- a/src/app/services/actions/query-action-creators.ts
+++ b/src/app/services/actions/query-action-creators.ts
@@ -105,9 +105,12 @@ export function runQuery(query: IQuery) {
 
     if(response && response.status === 401 && (CURRENT_RETRIES < MAX_NUMBER_OF_RETRIES)) {
       const successful = await runReAuthenticatedRequest(response);
-      if(successful){ dispatch(runQuery(query)); }
-      return;
+      if(successful){
+        dispatch(runQuery(query));
+        return;
+      }
     }
+
     dispatch(setQueryResponseStatus(status));
 
     return dispatch(


Test patch:
diff --git a/src/tests/ui/authenticated-experiences/authenticated-experiences.spec.ts b/src/tests/ui/authenticated-experiences/authenticated-experiences.spec.ts
index 105ed040..ac5b2f18 100644
--- a/src/tests/ui/authenticated-experiences/authenticated-experiences.spec.ts
+++ b/src/tests/ui/authenticated-experiences/authenticated-experiences.spec.ts
@@ -23,6 +23,16 @@ test.describe('Run query', () => {
     await expect(authenticatedPage.locator('text=/.*"displayName": "Megan Bowen".*/')).not.toBeVisible();
   });
 
+  test('Run query button does not hung on queries that return 401 or 403 results', async () => {
+    await authenticatedPage.getByRole('textbox', { name: 'More Info' }).click();
+    await authenticatedPage.locator('.ms-TextField-fieldGroup').click();
+    await authenticatedPage.getByRole('textbox', { name: 'More Info' }).clear();
+    await authenticatedPage.getByRole('textbox', { name: 'More Info' }).fill('https://graph.microsoft.com/v1.0/deviceAppManagement/managedAppPolicies');
+    await authenticatedPage.getByRole('button', { name: 'Run query' }).click();
+    expect(authenticatedPage.getByText('"Forbidden"')).toBeDefined();
+    expect(authenticatedPage.getByRole('button', { name: 'Run query' })).toBeDefined();
+  })
+
 });
 
 test.describe('Request', () => {