Skip to content

Commit b3e3cb4

Browse files
committed
style: 로그 추가
1 parent 25435b3 commit b3e3cb4

7 files changed

Lines changed: 265 additions & 181 deletions

File tree

DevLog/Infra/Common/Logger.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class Logger {
5555
) {
5656
var fullMessage = message
5757
if let error = error {
58-
fullMessage += " | Error: \(error.localizedDescription)"
58+
fullMessage += " | Error: \(error)"
5959
}
6060
log(fullMessage, type: .error, file: file, function: function, line: line)
6161
}
@@ -69,7 +69,7 @@ final class Logger {
6969
) {
7070
var fullMessage = message
7171
if let error = error {
72-
fullMessage += " | Error: \(error.localizedDescription)"
72+
fullMessage += " | Error: \(error)"
7373
}
7474
log(fullMessage, type: .fault, file: file, function: function, line: line)
7575
}

DevLog/Infra/Service/AuthService.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ final class AuthService {
5050
func deleteFirestoreUserData() async throws {
5151
logger.info("Deleting Firestore user data")
5252

53-
let deleteFunction = functions.httpsCallable("deleteUserFirestoreData")
54-
_ = try await deleteFunction.call()
53+
do {
54+
let deleteFunction = functions.httpsCallable("deleteUserFirestoreData")
55+
_ = try await deleteFunction.call()
56+
} catch {
57+
logger.error("Failed to delete Firestore user data", error: error)
58+
throw error
59+
}
5560
}
5661

5762
func deleteCurrentUser() async throws {
@@ -62,7 +67,12 @@ final class AuthService {
6267
throw AuthError.notAuthenticated
6368
}
6469

65-
try await currentUser.delete()
70+
do {
71+
try await currentUser.delete()
72+
} catch {
73+
logger.error("Failed to delete FirebaseAuth current user", error: error)
74+
throw error
75+
}
6676
}
6777

6878
func clearCurrentSession() async throws {
@@ -73,6 +83,12 @@ final class AuthService {
7383
} catch {
7484
logger.error("Failed to delete FCM token while clearing session", error: error)
7585
}
76-
try Auth.auth().signOut()
86+
87+
do {
88+
try Auth.auth().signOut()
89+
} catch {
90+
logger.error("Failed to sign out while clearing session", error: error)
91+
throw error
92+
}
7793
}
7894
}

DevLog/Infra/Service/PushNotificationService.swift

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,30 @@ final class PushNotificationService {
4141

4242
/// 푸시 알림 시간 설정
4343
func fetchPushNotificationTime() async throws -> DateComponents {
44+
logger.info("Fetching push notification time")
45+
4446
guard let uid = Auth.auth().currentUser?.uid else {
47+
logger.error("User not authenticated")
4548
throw AuthError.notAuthenticated
4649
}
4750

48-
let settingsRef = store.document("users/\(uid)/userData/settings")
49-
let doc = try await settingsRef.getDocument()
51+
do {
52+
let settingsRef = store.document("users/\(uid)/userData/settings")
53+
let doc = try await settingsRef.getDocument()
5054

51-
guard let hour = doc.data()?["pushNotificationHour"] as? Int else {
52-
throw FirestoreError.dataNotFound("pushNotificationHour")
53-
}
55+
guard let hour = doc.data()?["pushNotificationHour"] as? Int else {
56+
throw FirestoreError.dataNotFound("pushNotificationHour")
57+
}
5458

55-
guard let minute = doc.data()?["pushNotificationMinute"] as? Int else {
56-
throw FirestoreError.dataNotFound("pushNotificationMinute")
57-
}
59+
guard let minute = doc.data()?["pushNotificationMinute"] as? Int else {
60+
throw FirestoreError.dataNotFound("pushNotificationMinute")
61+
}
5862

59-
return DateComponents(hour: hour, minute: minute)
63+
return DateComponents(hour: hour, minute: minute)
64+
} catch {
65+
logger.error("Failed to fetch push notification time", error: error)
66+
throw error
67+
}
6068
}
6169

6270
/// 푸시 알림 설정 업데이트
@@ -94,35 +102,40 @@ final class PushNotificationService {
94102
_ notificationQuery: PushNotificationQuery,
95103
cursor: PushNotificationCursorDTO?
96104
) async throws -> PushNotificationPageResponse {
97-
guard let uid = Auth.auth().currentUser?.uid else { throw AuthError.notAuthenticated }
105+
do {
106+
guard let uid = Auth.auth().currentUser?.uid else { throw AuthError.notAuthenticated }
98107

99-
var firestoreQuery = makeQuery(uid: uid, query: notificationQuery)
108+
var firestoreQuery = makeQuery(uid: uid, query: notificationQuery)
100109

101-
if let cursor {
102-
firestoreQuery = firestoreQuery.start(after: [
103-
Timestamp(date: cursor.receivedAt),
104-
cursor.documentID
105-
])
106-
}
110+
if let cursor {
111+
firestoreQuery = firestoreQuery.start(after: [
112+
Timestamp(date: cursor.receivedAt),
113+
cursor.documentID
114+
])
115+
}
107116

108-
let snapshot = try await firestoreQuery
109-
.limit(to: notificationQuery.pageSize)
110-
.getDocuments()
117+
let snapshot = try await firestoreQuery
118+
.limit(to: notificationQuery.pageSize)
119+
.getDocuments()
111120

112-
let items = snapshot.documents.compactMap { makeResponse(from: $0) }
121+
let items = snapshot.documents.compactMap { makeResponse(from: $0) }
113122

114-
let nextCursor: PushNotificationCursorDTO? = snapshot.documents.last.map { document in
115-
guard let receivedAt = document.data()[Key.receivedAt.rawValue] as? Timestamp else {
116-
return nil
117-
}
123+
let nextCursor: PushNotificationCursorDTO? = snapshot.documents.last.map { document in
124+
guard let receivedAt = document.data()[Key.receivedAt.rawValue] as? Timestamp else {
125+
return nil
126+
}
118127

119-
return PushNotificationCursorDTO(
120-
receivedAt: receivedAt.dateValue(),
121-
documentID: document.documentID
122-
)
123-
} ?? nil
128+
return PushNotificationCursorDTO(
129+
receivedAt: receivedAt.dateValue(),
130+
documentID: document.documentID
131+
)
132+
} ?? nil
124133

125-
return PushNotificationPageResponse(items: items, nextCursor: nextCursor)
134+
return PushNotificationPageResponse(items: items, nextCursor: nextCursor)
135+
} catch {
136+
logger.error("Failed to request notifications", error: error)
137+
throw error
138+
}
126139
}
127140

128141
func observeNotifications(
@@ -160,37 +173,47 @@ final class PushNotificationService {
160173

161174
/// 푸시 알림 기록 삭제
162175
func deleteNotification(_ notificationID: String) async throws {
163-
guard let uid = Auth.auth().currentUser?.uid else { throw AuthError.notAuthenticated }
176+
do {
177+
guard let uid = Auth.auth().currentUser?.uid else { throw AuthError.notAuthenticated }
164178

165-
let docRef = store.collection("users/\(uid)/notifications").document(notificationID)
179+
let docRef = store.collection("users/\(uid)/notifications").document(notificationID)
166180

167-
try await docRef.delete()
181+
try await docRef.delete()
182+
} catch {
183+
logger.error("Failed to delete notification", error: error)
184+
throw error
185+
}
168186
}
169187

170188
/// 푸시 알림 읽음/안읽음 토글
171189
func toggleNotificationRead(_ todoId: String) async throws {
172190
logger.info("Toggling notification read for todoId: \(todoId)")
173191

174-
guard let uid = Auth.auth().currentUser?.uid else {
175-
logger.error("User not authenticated")
176-
throw AuthError.notAuthenticated
177-
}
192+
do {
193+
guard let uid = Auth.auth().currentUser?.uid else {
194+
logger.error("User not authenticated")
195+
throw AuthError.notAuthenticated
196+
}
178197

179-
let collection = store.collection("users/\(uid)/notifications")
180-
let snapshot = try await collection.whereField("todoId", isEqualTo: todoId).getDocuments()
198+
let collection = store.collection("users/\(uid)/notifications")
199+
let snapshot = try await collection.whereField("todoId", isEqualTo: todoId).getDocuments()
181200

182-
guard let document = snapshot.documents.first else {
183-
logger.error("Notification not found for todoId: \(todoId)")
184-
throw FirestoreError.dataNotFound("notification")
185-
}
201+
guard let document = snapshot.documents.first else {
202+
logger.error("Notification not found for todoId: \(todoId)")
203+
throw FirestoreError.dataNotFound("notification")
204+
}
186205

187-
guard let currentValue = document.data()["isRead"] as? Bool else {
188-
logger.error("isRead not found for notification: \(document.documentID)")
189-
throw FirestoreError.dataNotFound("isRead")
190-
}
206+
guard let currentValue = document.data()["isRead"] as? Bool else {
207+
logger.error("isRead not found for notification: \(document.documentID)")
208+
throw FirestoreError.dataNotFound("isRead")
209+
}
191210

192-
try await document.reference.updateData(["isRead": !currentValue])
193-
logger.info("Successfully toggled notification read")
211+
try await document.reference.updateData(["isRead": !currentValue])
212+
logger.info("Successfully toggled notification read")
213+
} catch {
214+
logger.error("Failed to toggle notification read", error: error)
215+
throw error
216+
}
194217
}
195218
}
196219

DevLog/Infra/Service/SocialLogin/AppleAuthenticationService.swift

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,51 +89,66 @@ final class AppleAuthenticationService: AuthenticationService {
8989
}
9090

9191
func signOut(_ uid: String) async throws {
92-
let infoRef = store.document("users/\(uid)/userData/tokens")
93-
let doc = try await infoRef.getDocument()
92+
do {
93+
let infoRef = store.document("users/\(uid)/userData/tokens")
94+
let doc = try await infoRef.getDocument()
9495

95-
if doc.exists {
96-
try await infoRef.updateData(["fcmToken": FieldValue.delete()])
97-
}
96+
if doc.exists {
97+
try await infoRef.updateData(["fcmToken": FieldValue.delete()])
98+
}
9899

99-
try await messaging.deleteToken()
100+
try await messaging.deleteToken()
100101

101-
try Auth.auth().signOut()
102+
try Auth.auth().signOut()
103+
} catch {
104+
logger.error("Failed to sign out with Apple", error: error)
105+
throw error
106+
}
102107
}
103108

104109
func deleteAuth(_ uid: String) async throws {
105-
let token = try await refreshAppleAccessToken()
110+
do {
111+
let token = try await refreshAppleAccessToken()
106112

107-
try await revokeAppleAccessToken(token: token)
113+
try await revokeAppleAccessToken(token: token)
114+
} catch {
115+
logger.error("Failed to delete Apple auth", error: error)
116+
throw error
117+
}
108118
}
109119

110120
func link(uid: String, email: String) async throws {
111-
let response = try await authenticateWithAppleAsync()
121+
do {
122+
let response = try await authenticateWithAppleAsync()
112123

113-
let nonce = response.nonce
114-
let credential = response.credential
115-
let authorizationCode = response.authorizationCode
116-
let idTokenString = response.idTokenString
124+
let nonce = response.nonce
125+
let credential = response.credential
126+
let authorizationCode = response.authorizationCode
127+
let idTokenString = response.idTokenString
117128

118-
let refreshToken = try await requestAppleRefreshToken(uid: uid, authorizationCode: authorizationCode)
129+
let refreshToken = try await requestAppleRefreshToken(uid: uid, authorizationCode: authorizationCode)
119130

120-
guard let appleEmail = credential.email else {
121-
try await revokeAppleAccessToken(token: refreshToken)
122-
throw EmailFetchError.emailNotFound
123-
}
131+
guard let appleEmail = credential.email else {
132+
try await revokeAppleAccessToken(token: refreshToken)
133+
throw EmailFetchError.emailNotFound
134+
}
124135

125-
if appleEmail != email {
126-
try await revokeAppleAccessToken(token: refreshToken)
127-
throw EmailFetchError.emailMismatch
128-
}
136+
if appleEmail != email {
137+
try await revokeAppleAccessToken(token: refreshToken)
138+
throw EmailFetchError.emailMismatch
139+
}
129140

130-
let appleCredential = OAuthProvider.credential(
131-
providerID: providerID,
132-
idToken: idTokenString,
133-
rawNonce: nonce
134-
)
141+
let appleCredential = OAuthProvider.credential(
142+
providerID: providerID,
143+
idToken: idTokenString,
144+
rawNonce: nonce
145+
)
135146

136-
try await user?.link(with: appleCredential)
147+
try await user?.link(with: appleCredential)
148+
} catch {
149+
logger.error("Failed to link Apple account", error: error)
150+
throw error
151+
}
137152
}
138153

139154
func unlink(_ uid: String) async throws {

DevLog/Infra/Service/SocialLogin/GithubAuthenticationService.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,30 @@ final class GithubAuthenticationService: NSObject, AuthenticationService {
6868
}
6969

7070
func signOut(_ uid: String) async throws {
71-
let infoRef = store.document("users/\(uid)/userData/tokens")
72-
let doc = try await infoRef.getDocument()
71+
do {
72+
let infoRef = store.document("users/\(uid)/userData/tokens")
73+
let doc = try await infoRef.getDocument()
7374

74-
if doc.exists {
75-
try await infoRef.updateData(["fcmToken": FieldValue.delete()])
76-
}
75+
if doc.exists {
76+
try await infoRef.updateData(["fcmToken": FieldValue.delete()])
77+
}
7778

78-
try await messaging.deleteToken()
79+
try await messaging.deleteToken()
7980

80-
try Auth.auth().signOut()
81+
try Auth.auth().signOut()
82+
} catch {
83+
logger.error("Failed to sign out with GitHub", error: error)
84+
throw error
85+
}
8186
}
8287

8388
func deleteAuth(_ uid: String) async throws {
84-
try await revokeAccessToken()
89+
do {
90+
try await revokeAccessToken()
91+
} catch {
92+
logger.error("Failed to delete GitHub auth", error: error)
93+
throw error
94+
}
8595
}
8696

8797
func link(uid: String, email: String) async throws {

0 commit comments

Comments
 (0)