Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Fix Leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
adelbios committed Nov 12, 2022
1 parent 4c994e2 commit 19a99ff
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Sources/PowerKit/Kit/Helper/PowerNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ private extension PowerNetwork {
}

func didResponseSuccess(_ response: Response, target: TargetType) {
self.checkErrorModel(response)
self.printRespinseResultUsing(target, response: response, data: response.data)
guard requestFailure(response.statusCode) == false else { return }
guard checkIfDataCorrupted(response.data) == false else { return }
self.data = response.data
self.checkErrorModel(response) { [weak self] in
guard let self = self else { return }
self.printRespinseResultUsing(target, response: response, data: response.data)
guard self.requestFailure(response.statusCode) == false else { return }
guard self.checkIfDataCorrupted(response.data) == false else { return }
self.data = response.data
}
}

func didRequestFailure(_ moyaError : MoyaError){
Expand Down Expand Up @@ -134,11 +136,11 @@ private extension PowerNetwork {
return self.requestFailure(9999)
}

func checkErrorModel(_ response: Response) {
func checkErrorModel(_ response: Response, _ completion: @escaping () -> ()) {
let json = JSONDecoder()
json.implement(useKeyDecodingStrategy: true, type: ErrorModel.self, data: response.data) { [weak self] s in
guard let self = self else { return }
guard s.success == false && s.errorCode == 57716 else { return }
guard s.success == false && s.errorCode == 57716 else { completion(); return }
let _ = self.requestFailure(9999)
}
}
Expand Down

0 comments on commit 19a99ff

Please sign in to comment.