-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bb8805a
commit b0f4062
Showing
10 changed files
with
358 additions
and
40 deletions.
There are no files selected for viewing
21 changes: 15 additions & 6 deletions
21
src/components/data-external-tool/ExternalToolElementDisplayState.composable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
import { ExternalToolDisplayData } from "@/store/external-tool"; | ||
import { BusinessError } from "@/store/types/commons"; | ||
import { mapAxiosErrorToResponseError } from "@/utils/api"; | ||
import { ref, Ref } from "vue"; | ||
import { ExternalToolDisplayData } from "../../store/external-tool"; | ||
import { useErrorHandler } from "../error-handling/ErrorHandler.composable"; | ||
import { useContextExternalToolApi } from "./index"; | ||
|
||
export const useExternalToolElementDisplayState = () => { | ||
const { handleError } = useErrorHandler(); | ||
const { fetchDisplayDataCall } = useContextExternalToolApi(); | ||
const displayData: Ref<ExternalToolDisplayData | undefined> = ref(); | ||
const isLoading: Ref<boolean> = ref(false); | ||
const error: Ref<BusinessError | undefined> = ref(undefined); | ||
|
||
const fetchDisplayData = async ( | ||
contextExternalToolId: string | ||
): Promise<void> => { | ||
isLoading.value = true; | ||
error.value = undefined; | ||
|
||
try { | ||
displayData.value = await fetchDisplayDataCall(contextExternalToolId); | ||
} catch (error) { | ||
handleError(error); | ||
} catch (errorResponse) { | ||
const apiError = mapAxiosErrorToResponseError(errorResponse); | ||
|
||
error.value = { | ||
error: apiError, | ||
statusCode: apiError.code, | ||
message: apiError.message, | ||
}; | ||
} | ||
|
||
isLoading.value = false; | ||
}; | ||
|
||
return { | ||
isLoading, | ||
displayData, | ||
isLoading, | ||
error, | ||
fetchDisplayData, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.