Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/user.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class UserAPI {
return axiosInstance.put(`/password`, dto);
}

static deleteById(id: number): Promise<AxiosResponse<null>> {
return axiosInstance.delete(`/${id}`);
static delete(): Promise<AxiosResponse<null>> {
return axiosInstance.delete(`/`);
}
}
12 changes: 10 additions & 2 deletions src/components/room/RoomActiveRequestEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const acceptRequest = (reservationRequestId: number) => {
loadRequests();
})
.catch((err: AxiosError) => {
requestsError.value = err.message;
if (err.response?.status === 404) {
requestsError.value = "Reservation request not found or deleted.";
} else {
requestsError.value = (err.response?.data as { error: string })?.error ?? "An unknown error occurred.";
}
})
.finally(() => {
loading.value = false;
Expand All @@ -52,7 +56,11 @@ const rejectRequest = (reservationRequestId: number) => {
loadRequests();
})
.catch((err: AxiosError) => {
requestsError.value = err.message;
if (err.response?.status === 404) {
requestsError.value = "Reservation request not found or deleted.";
} else {
requestsError.value = (err.response?.data as { error: string })?.error ?? "An unknown error occurred.";
}
})
.finally(() => {
loading.value = false;
Expand Down
9 changes: 9 additions & 0 deletions src/views/room/RoomDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const room = ref<RoomDTO | null>(null);
const roomAvailability = ref<RoomAvailabilityListDTO | null>(null);
const auth = useAuthStore();
const loading = ref(false);
const error = ref('');

onMounted(() => { auth.checkLocalStorage(); });
onMounted(() => loadRoom());
Expand All @@ -29,6 +30,11 @@ const loadRoom = () => {
RoomAPI.findById(roomId).then((res: AxiosResponse<RoomDTO>) => {
room.value = res.data;
}).catch((err: AxiosError) => {
if (err.response?.status === 404) {
error.value = "Room not found or deleted.";
} else {
error.value = (err.response?.data as { error: string })?.error ?? "An unknown error occurred.";
}
console.error(err);
}).finally(() => {
loading.value = false;
Expand Down Expand Up @@ -58,6 +64,9 @@ const gotoReservation = () => {
<div v-if="loading">
<ProgressBar mode="indeterminate" style="height: 6px"></ProgressBar>
</div>

<Message v-show="error.length > 0" style="margin: 7px;" severity="error" size="medium" variant="simple">{{ error }}</Message>

Comment on lines +67 to +69

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the error http response code is 404, could we add a custom message? Since this is RoomDetails, we know that a 404 means "Room not found or deleted".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I didn’t do that intentionally, because I thought hardcoding it wouldn’t be a smart long-term solution. But I agree it would improve UX, so I implemented it. I also handled a similar case where a reservation request remains in flight on the host side after the guest account is deleted. ff7ec2c

<div v-if="room">
<h2>{{ room.name }}</h2>
<p>{{ room.description }}</p>
Expand Down
2 changes: 2 additions & 0 deletions src/views/user/UserLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const doLogin = () => {
}).catch((err: AxiosError) => {
if (err.response?.status == 400) {
error.value = "Unknown user or password";
} else if (err.response?.status == 401) {
error.value = "Account is deleted";
} else {
console.error(err);
error.value = "Unknown error. Check the console";
Expand Down
4 changes: 2 additions & 2 deletions src/views/user/UserSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ const doDeleteUser = () => {

formDeleteLoading.value = true;

UserAPI.deleteById(auth.id).then(() => {
UserAPI.delete().then(() => {
auth.logout();
router.push("/");
}).catch((err: AxiosError) => {
errorDelete.value = err.response.data as string;
errorDelete.value = (err.response?.data as { error: string })?.error ?? "An unknown error occurred.";
console.error(err);
}).finally(() => {
formDeleteLoading.value = false;
Expand Down