fix(club): enhance error handling in loadClub method
- Improved error handling in the loadClub method to check response status directly, ensuring proper fallback club data is used when access is denied. - Updated logic to throw an error for unexpected response statuses, enhancing user feedback and robustness in access management.
This commit is contained in:
@@ -130,18 +130,20 @@ export default {
|
||||
const clubId = this.getClubId();
|
||||
this.accessRequested = false;
|
||||
const response = await apiClient.get(`/clubs/${clubId}`);
|
||||
this.club = response.data || { name: '' };
|
||||
this.accessAllowed = true;
|
||||
} catch (error) {
|
||||
// Kein Zugriff: Status vom Backend nutzen (requested/notrequested)
|
||||
if (error?.response?.status === 403 && error?.response?.data?.status) {
|
||||
const clubId = this.getClubId();
|
||||
// apiClient behandelt 4xx als "erfolgreich" -> Status selbst prüfen
|
||||
if (response.status === 403 && response.data?.status) {
|
||||
const club = this.clubs.find(c => String(c.id) === String(clubId));
|
||||
this.club = club || { name: '' };
|
||||
this.accessAllowed = false;
|
||||
this.accessRequested = error.response.data.status === 'requested';
|
||||
this.accessRequested = response.data.status === 'requested';
|
||||
return;
|
||||
}
|
||||
if (response.status >= 400) {
|
||||
throw new Error('club_access_error');
|
||||
}
|
||||
this.club = response.data || { name: '' };
|
||||
this.accessAllowed = true;
|
||||
} catch (error) {
|
||||
this.accessAllowed = false;
|
||||
const message = safeErrorMessage(error, this.$t('club.accessDenied'));
|
||||
await this.showInfo(this.$t('messages.error'), message, '', 'error');
|
||||
|
||||
Reference in New Issue
Block a user