Merge pull request 'fixed admin search loading issues and improved error handling' (#15) from admin-search-bug-fixes into main
Reviewed-on: #15
This commit is contained in:
commit
1524154bfb
1 changed files with 21 additions and 22 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import type { Movie } from "~/types/movie";
|
||||
import "lazysizes";
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
|
@ -42,29 +43,27 @@ const findMovies = async function (e: Event) {
|
|||
return;
|
||||
}
|
||||
|
||||
const { data, error } = await useFetch<Movie[]>(
|
||||
`${config.public.apiURL}/movies/search?q=${searchTerm}`,
|
||||
{
|
||||
$fetch<Movie[]>(`${config.public.apiURL}/movies/search?q=${searchTerm}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-type": "application/json",
|
||||
Authorization: `Token ${useCookie("token").value}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (error.value) {
|
||||
if (error.value.statusCode === 401) {
|
||||
alert("Unauthorized");
|
||||
}
|
||||
} else {
|
||||
if (!data.value) {
|
||||
alert("No movies found.");
|
||||
} else {
|
||||
movies.value = data.value || [];
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
movies.value = data;
|
||||
loading.value = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.statusCode === 401) {
|
||||
navigateTo("/login");
|
||||
} else if (err.statusCode === 404) {
|
||||
alert("No movies found");
|
||||
loading.value = false;
|
||||
} else {
|
||||
alert("An error occurred. Please try again later.");
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue