@@ -7,7 +7,7 @@ import {executeQueryHook} from "./hooks/executeQueryHook"
77import { AccessControlDashboard } from "@terminusdb/terminusdb-access-control-component"
88import { useLocation } from "react-router-dom"
99import { createClientUser , formatSchema } from "./clientUtils"
10-
10+ import { formatErrorMessage } from './hooks/hookUtils'
1111export const WOQLContext = React . createContext ( )
1212export const WOQLClientObj = ( ) => useContext ( WOQLContext )
1313
@@ -128,13 +128,7 @@ export const WOQLClientProvider = ({children, params}) => {
128128 setAccessControl ( clientAccessControl )
129129 setWoqlClient ( dbClient )
130130 } catch ( err ) {
131- let message = err . message
132- if ( err . data && err . data [ "api:message" ] ) {
133- message = err . data [ "api:message" ]
134- console . log ( "ERROR_DATA" , message )
135- } else if ( message . indexOf ( "Network Error" ) > - 1 ) {
136- message = "Network Error"
137- }
131+ const message = formatErrorMessage ( err )
138132 setError ( message )
139133 } finally {
140134 setLoadingServer ( false )
@@ -307,32 +301,37 @@ export const WOQLClientProvider = ({children, params}) => {
307301
308302 // review
309303 async function changeOrganization ( orgName , setDataP , hubClient , accessControlDash ) {
310- hubClient = hubClient || woqlClient
311- accessControlDash = accessControlDash || accessControlDashboard
312- //this set the organization name and reset the databases list to empty
313- hubClient . organization ( orgName )
314- // this failed if the organization does not exists
315- await accessControlDash . callGetUserTeamRole ( clientUser . user , orgName )
316-
317- //I use this for now to not call getDatabases
318- if ( hubClient . userOrganizations ( ) . length > 0 ) {
319- const hh = hubClient . userOrganizations ( ) ;
320- const dbs = hubClient . userOrganizations ( ) . find ( element => element [ 'name' ] === orgName )
321- //console.log("DATABASES", dbs)
322- const dbList = dbs && dbs . databases ? dbs . databases : [ ]
323- hubClient . databases ( dbList )
324- }
325- //this is for change the base url api for the proxy
326- if ( opts . connection_type !== "LOCAL" ) {
327- hubClient . connectionConfig . api_extension = `${ orgName } /api/`
328- //load the list of system roles
329- accessControlDash . callGetRolesList ( )
304+ try {
305+ hubClient = hubClient || woqlClient
306+ accessControlDash = accessControlDash || accessControlDashboard
307+ //this set the organization name and reset the databases list to empty
308+ hubClient . organization ( orgName )
309+ // this failed if the organization does not exists
310+ await accessControlDash . callGetUserTeamRole ( clientUser . user , orgName )
311+
312+ //I use this for now to not call getDatabases
313+ if ( hubClient . userOrganizations ( ) . length > 0 ) {
314+ const hh = hubClient . userOrganizations ( ) ;
315+ const dbs = hubClient . userOrganizations ( ) . find ( element => element [ 'name' ] === orgName )
316+ //console.log("DATABASES", dbs)
317+ const dbList = dbs && dbs . databases ? dbs . databases : [ ]
318+ hubClient . databases ( dbList )
319+ }
320+ //this is for change the base url api for the proxy
321+ if ( opts . connection_type !== "LOCAL" ) {
322+ hubClient . connectionConfig . api_extension = `${ orgName } /api/`
323+ //load the list of system roles
324+ accessControlDash . callGetRolesList ( )
325+ }
326+
327+ localStorage . setItem ( "Org" , orgName )
328+ const dataP = setDataP || false
329+ //reset database and commit head
330+ setDataProduct ( dataP , hubClient , accessControlDash )
331+ } catch ( err ) {
332+ const message = formatErrorMessage ( err )
333+ setError ( message )
330334 }
331-
332- localStorage . setItem ( "Org" , orgName )
333- const dataP = setDataP || false
334- //reset database and commit head
335- setDataProduct ( dataP , hubClient , accessControlDash )
336335 }
337336
338337 //get the list of databases
0 commit comments