fix(club): improve error handling and access logic in loadClub method
- Refactored the loadClub method to handle access checks more effectively, ensuring fallback club data is used when access is denied. - Enhanced error handling to manage access request status and provide appropriate user feedback based on backend responses.
This commit is contained in:
@@ -128,17 +128,20 @@ export default {
|
||||
async loadClub() {
|
||||
try {
|
||||
const clubId = this.getClubId();
|
||||
// Wenn keine Berechtigung: Clubnamen aus der Liste verwenden, kein /clubs/:id Request
|
||||
if (!this.canAccessClub()) {
|
||||
const club = this.clubs.find(c => String(c.id) === String(clubId));
|
||||
this.club = club || { name: '' };
|
||||
this.accessAllowed = false;
|
||||
return;
|
||||
}
|
||||
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();
|
||||
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';
|
||||
return;
|
||||
}
|
||||
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