Skip to content

Commit

Permalink
Check cancellation before reporting error
Browse files Browse the repository at this point in the history
  • Loading branch information
shp7724 committed Oct 12, 2024
1 parent 1a7df32 commit 2248b4a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions SNUTT-2022/SNUTT/Repositories/NetworkUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ extension DataTask {
if let data = await response.data,
let errDto = try? JSONDecoder().decode(ErrorDto.self, from: data)
{
try Task.checkCancellation()
let errCode = ErrorCode(rawValue: errDto.errcode)
var requestInfo = await collectRequestInfo()
requestInfo["ErrorMessage"] = errCode?.errorMessage
Expand All @@ -129,13 +130,13 @@ extension DataTask {
throw STError(errCode ?? .SERVER_FAULT)
}
}

if let dto = try? await value {
return dto
}

try Task.checkCancellation()
let requestInfo = await collectRequestInfo()
Crashlytics.crashlytics().record(error: NSError(domain: "UNKNOWN_ERROR", code: -1, userInfo: requestInfo))
try Task.checkCancellation()
throw STError(.SERVER_FAULT)
}

Expand Down

0 comments on commit 2248b4a

Please sign in to comment.