File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //
2+ // DecodingErrorFormatter.swift
3+ // GoodNetworking
4+ //
5+ // Created by Filip Šašala on 29/09/2025.
6+ //
7+
8+ import Foundation
9+
10+ internal extension DecodingError {
11+
12+ var prettyPrinted : String {
13+ switch self {
14+ case . typeMismatch( _, let context) ,
15+ . valueNotFound( _, let context) ,
16+ . keyNotFound( _, let context) ,
17+ . dataCorrupted( let context) :
18+ """
19+ ⛔️ Decoding failed - \( context. debugDescription)
20+ Coding path: \( context. codingPath. prettyPrinted)
21+ """
22+
23+ @unknown default :
24+ " ⛔️ Decoding failed - unknown error "
25+ }
26+ }
27+
28+ }
29+
30+ private extension Array where Element == CodingKey {
31+
32+ var prettyPrinted : String {
33+ map { $0. prettyPrinted } . joined ( separator: " → " )
34+ }
35+
36+ }
37+
38+ private extension CodingKey {
39+
40+ var prettyPrinted : String {
41+ if let intValue = intValue {
42+ return " [ \( intValue) ] "
43+ }
44+ return stringValue
45+ }
46+
47+ }
Original file line number Diff line number Diff line change @@ -227,6 +227,12 @@ extension NetworkSession {
227227 let model = try decoder. decode ( T . self, from: data)
228228 return model
229229 } catch let error as DecodingError {
230+ logger. logNetworkEvent (
231+ message: error. prettyPrinted,
232+ level: . error,
233+ file: #file,
234+ line: #line
235+ )
230236 throw error. asNetworkError ( )
231237 } catch {
232238 throw URLError ( . cannotDecodeRawData) . asNetworkError ( )
You can’t perform that action at this time.
0 commit comments