Monitor decoding errors


I would like to monitor events for Decoding errors.
In the EventMonitor protocol I couldn't find and method useful.
DecodableResponseSerializer class would only throw the error without using the eventMonitor mechanism.
throw AFError.responseSerializationFailed(reason: .decodingFailed(error: error))

How can I achieve this globally in one single place instead of checking the error at each request response result?

Thank you.

This can be done by implementing request(_:didParseResponse:) which is called whenever a DataRequest or UploadRequest serializes a response. DownloadRequest has a similar event.

Thank you Jon, I was able to extract the decoding error in this method. :+1:

func request<Value>(_ request: DataRequest, didParseResponse response: DataResponse<Value, AFError>) {
      guard case let .responseSerializationFailed(reason) = response.error,
            case let .decodingFailed(error) = reason,
            let decodingError = error as? DecodingError else {
      // Do something with `decodingError`