Skip to content

Commit

Permalink
Make it refresh token if it says it's expired. Add highlight to curre…
Browse files Browse the repository at this point in the history
…nt day in timetable view.
  • Loading branch information
itsnotrin committed Dec 11, 2024
1 parent 8a2274d commit b6cb628
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions BetterClasscharts/MainTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ struct TimetableView: View {
Group {
if isCurrentDay(day) {
Theme.surfaceColor(for: appTheme, colorScheme: colorScheme)
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color.purple, lineWidth: 3)
)
} else {
selectedDay == day ? Theme.accentColor(for: appTheme) : Theme.surfaceColor(for: appTheme, colorScheme: colorScheme)
}
Expand Down
29 changes: 16 additions & 13 deletions BetterClasscharts/StudentClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,25 @@ class StudentClient {
request: @escaping (@escaping (Result<T, Error>) -> Void) -> Void
) {
request { result in
if case .failure(let error) = result,
let networkError = error as? NetworkError,
networkError == .sessionExpired {
// Session expired, refresh and retry once
checkAndRefreshSession { refreshResult in
switch refreshResult {
case .success:
// Token refreshed, retry the original request
request(completion)
case .failure(let refreshError):
// Token refresh failed, return the error
completion(.failure(refreshError))
if case .failure(let error) = result {
if let networkError = error as? NetworkError,
(networkError == .sessionExpired || networkError == .missingUserData) {
// Session expired or missing user data, refresh and retry once
checkAndRefreshSession { refreshResult in
switch refreshResult {
case .success:
// Token refreshed, retry the original request
request(completion)
case .failure(let refreshError):
// Token refresh failed, return the error
completion(.failure(refreshError))
}
}
} else {
// Not a session expiration or second attempt, return the result
completion(result)
}
} else {
// Not a session expiration or second attempt, return the result
completion(result)
}
}
Expand Down

0 comments on commit b6cb628

Please sign in to comment.