Skip to content

Commit

Permalink
optimize axios error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Nov 27, 2024
1 parent d180c4c commit d71a9e5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions resources/js/composables/album/albumRefresher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AlbumService from "@/services/album-service";
import { AuthStore } from "@/stores/Auth";
import { computed, Ref, ref } from "vue";
import axios, { AxiosError } from 'axios'

export function useAlbumRefresher(albumId: Ref<string>, auth: AuthStore, isLoginOpen: Ref<boolean>, nsfw_consented: Ref<string[]>) {
const isPasswordProtected = ref(false);
Expand Down Expand Up @@ -39,13 +40,16 @@ export function useAlbumRefresher(albumId: Ref<string>, auth: AuthStore, isLogin
}
photos.value = album.value?.photos ?? [];
isAlbumConsented.value = nsfw_consented.value.find((e) => e === albumId.value) !== undefined;
} catch (error) {
if (error.response.status === 401 && error.response.data.message === "Password required") {
isPasswordProtected.value = true;
} else if (error.response.status === 403 && error.response.data.message === "Password required") {
isPasswordProtected.value = true;
} else if (error.response.status === 401) {
isLoginOpen.value = true;
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
if (axiosError.response?.status === 401 && axiosError.response?.data?.message === "Password required") {
isPasswordProtected.value = true;
} else if (axiosError.response?.status === 403 && axiosError.response?.data?.message === "Password required") {
isPasswordProtected.value = true;
} else if (axiosError.response?.status === 401) {
isLoginOpen.value = true;
}
} else {
console.error(error);
}
Expand Down

0 comments on commit d71a9e5

Please sign in to comment.