-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0068a3d
commit adf6116
Showing
2 changed files
with
30 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
const GameAPI = { | ||
fetchGameDetails: function (gameId) { | ||
const token = localStorage.getItem('token'); | ||
|
||
if (!gameId) { | ||
GameUtils.showError('Invalid game ID'); | ||
return; | ||
} | ||
|
||
$.ajax({ | ||
url: `/api/games/${gameId}`, | ||
method: 'GET', | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
'Authorization': `Bearer ${token}`, | ||
'Content-Type': 'application/json' | ||
}, | ||
success: function (game) { | ||
GameDisplay.displayGameDetails(game); | ||
if (game) { | ||
GameDisplay.displayGameDetails(game); | ||
} else { | ||
GameUtils.showError('Game not found'); | ||
} | ||
}, | ||
error: function (xhr, status, error) { | ||
GameUtils.showError( | ||
'Error fetching game details: ' + | ||
(xhr.responseJSON ? xhr.responseJSON.error : 'Unknown error') | ||
); | ||
}, | ||
let errorMessage = 'Error fetching game details'; | ||
if (xhr.status === 404) { | ||
errorMessage = 'Game not found'; | ||
} else if (xhr.responseJSON && xhr.responseJSON.error) { | ||
errorMessage += ': ' + xhr.responseJSON.error; | ||
} | ||
GameUtils.showError(errorMessage); | ||
} | ||
}); | ||
}, | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters