Skip to content

Commit 6741556

Browse files
committed
✨ api: Add timeout error handling and simplify theme payloads
1 parent 403d871 commit 6741556

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

SNUTT/Modules/Feature/APIClientInterface/Sources/Error/APIClientError.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Copyright © 2025 wafflestudio.com. All rights reserved.
66
//
77

8+
import Foundation
89
import OpenAPIRuntime
910

1011
public enum APIClientError: Error {
@@ -53,4 +54,14 @@ extension Error {
5354
false
5455
}
5556
}
57+
58+
public var isTimeoutError: Bool {
59+
switch self {
60+
case let error as ClientError:
61+
let nsError = error.underlyingError as NSError
62+
return nsError.domain == NSURLErrorDomain && nsError.code == NSURLErrorTimedOut
63+
default:
64+
return false
65+
}
66+
}
5667
}

SNUTT/Modules/Feature/Themes/Sources/Infra/ThemeAPIRepository.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,16 @@ public struct ThemeAPIRepository: ThemeRepository {
4040
}
4141

4242
extension Theme {
43+
private var colorPayloads: [Components.Schemas.ColorSet] {
44+
colors.map { .init(bg: $0.bgHex, fg: $0.fgHex) }
45+
}
46+
4347
fileprivate func toAddPayload() -> Components.Schemas.TimetableThemeAddRequestDto {
44-
.init(
45-
colors: colors.map { .init(bg: $0.bgHex, fg: $0.fgHex) },
46-
name: name
47-
)
48+
.init(colors: colorPayloads, name: name)
4849
}
4950

5051
fileprivate func toModifyPayload() -> Components.Schemas.TimetableThemeModifyRequestDto {
51-
.init(
52-
colors: colors.map { .init(bg: $0.bgHex, fg: $0.fgHex) },
53-
name: name
54-
)
52+
.init(colors: colorPayloads, name: name)
5553
}
5654
}
5755

0 commit comments

Comments
 (0)