From 0f76136c9f48c12cbefc4debcd34b085951b3bf0 Mon Sep 17 00:00:00 2001 From: Joe Bottigliero <694253+jbottigliero@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:22:15 -0500 Subject: [PATCH] feat: introduces authorization_parameters error handling --- components/file-browser/FileBrowser.tsx | 1 - components/file-browser/FileBrowserError.tsx | 50 ++++++++----------- .../file-browser/FileBrowserViewMenu.tsx | 1 - package-lock.json | 8 +-- package.json | 2 +- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/components/file-browser/FileBrowser.tsx b/components/file-browser/FileBrowser.tsx index 5011b3a..bdac3c8 100644 --- a/components/file-browser/FileBrowser.tsx +++ b/components/file-browser/FileBrowser.tsx @@ -115,7 +115,6 @@ export default function FileBrowser({ type: "RESET_ITEMS", }); } - console.log(fileBrowser.view.show_hidden); const response = await transfer.fileOperations.ls(collection, { headers: { Authorization: `Bearer ${auth.authorization?.tokens.transfer?.access_token}`, diff --git a/components/file-browser/FileBrowserError.tsx b/components/file-browser/FileBrowserError.tsx index 2acba2e..5486de3 100644 --- a/components/file-browser/FileBrowserError.tsx +++ b/components/file-browser/FileBrowserError.tsx @@ -14,7 +14,11 @@ import { } from "@chakra-ui/react"; import { useGlobusAuth } from "../globus-auth-context/useGlobusAuth"; - +import { + isErrorWellFormed, + isConsentRequiredError, + isAuthorizationRequirementsError, +} from "@globus/sdk/cjs/lib/core/authorization/AuthorizationManager"; import type { DirectoryListingError } from "@globus/sdk/cjs/lib/services/transfer/service/file-operations"; export default function FileBrowserError({ @@ -24,20 +28,9 @@ export default function FileBrowserError({ }) { const auth = useGlobusAuth(); - const isWellFormedError = ( - error: unknown, - ): error is DirectoryListingError => { - return ( - typeof error === "object" && - error !== null && - "code" in error && - "message" in error - ); - }; - - const isDirectoryListingError = isWellFormedError(error); + const isWellFormed = isErrorWellFormed(error); - if (isDirectoryListingError && error.code === "ConsentRequired") { + if (isWellFormed && isConsentRequiredError(error)) { return ( @@ -65,11 +58,7 @@ export default function FileBrowserError({ ); } - if ( - isDirectoryListingError && - error.code === "PermissionDenied" && - "authorization_parameters" in error - ) { + if (isWellFormed && isAuthorizationRequirementsError(error)) { /* eslint-disable camelcase */ const { session_message, @@ -83,15 +72,14 @@ export default function FileBrowserError({ - {error.message} + {session_message || error.message} - {session_message && {session_message}} - + {session_required_mfa && ( Requires Multi-Factor Authentication )} - {session_required_identities && ( + {session_required_identities?.length && ( Required Identities:{" "} {session_required_identities.join(", ")} @@ -100,18 +88,20 @@ export default function FileBrowserError({ {session_required_single_domain && session_required_single_domain?.length && ( - Required Single Domain:{" "} + Required Domain(s):{" "} {session_required_single_domain} )} - {/* */} + Address + @@ -153,7 +143,7 @@ export default function FileBrowserError({ ); } - if (isDirectoryListingError) { + if (isWellFormed) { return ( diff --git a/components/file-browser/FileBrowserViewMenu.tsx b/components/file-browser/FileBrowserViewMenu.tsx index 2010441..e785613 100644 --- a/components/file-browser/FileBrowserViewMenu.tsx +++ b/components/file-browser/FileBrowserViewMenu.tsx @@ -25,7 +25,6 @@ export default function FileBrowserViewMenu() { type="checkbox" defaultValue={[state.view.show_hidden ? "show_hidden" : ""]} onChange={(value) => { - console.log(value); dispatch({ type: "SET_VIEW_SHOW_HIDDEN", payload: value.includes("show_hidden"), diff --git a/package-lock.json b/package-lock.json index 388082b..7e72b43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@chakra-ui/react": "^2.8.2", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", - "@globus/sdk": "^3.0.0-alpha.4", + "@globus/sdk": "^3.0.0-alpha.5", "framer-motion": "^11.0.5", "next": "14.1.0", "react": "^18", @@ -1633,9 +1633,9 @@ } }, "node_modules/@globus/sdk": { - "version": "3.0.0-alpha.4", - "resolved": "https://registry.npmjs.org/@globus/sdk/-/sdk-3.0.0-alpha.4.tgz", - "integrity": "sha512-F+6P0XIkbgOThRift9vh/ZvZ7WqJifDqqwXQhPOJlSMY7tASokDfPcKuKIhmB3Deu2ySCiS/XoQ+EXrCCTOBaw==", + "version": "3.0.0-alpha.5", + "resolved": "https://registry.npmjs.org/@globus/sdk/-/sdk-3.0.0-alpha.5.tgz", + "integrity": "sha512-00sm+IgNyW+VbRcQoCfOwLh3J09XLIj6vBw7gZZ/LKAg9qIkkWQRv/7EKf6T25pzQ1juJHxOCoxSBNL5jJkqZw==", "dependencies": { "cross-fetch": "^4.0.0", "js-pkce": "^1.2.1" diff --git a/package.json b/package.json index 1834167..2608a8e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@chakra-ui/react": "^2.8.2", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", - "@globus/sdk": "^3.0.0-alpha.4", + "@globus/sdk": "^3.0.0-alpha.5", "framer-motion": "^11.0.5", "next": "14.1.0", "react": "^18",