Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status Code is not shown #58

Closed
jubakong opened this issue Nov 12, 2021 · 5 comments
Closed

Status Code is not shown #58

jubakong opened this issue Nov 12, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@jubakong
Copy link

Pulse looks like it is such an amazing network logger, but PulseUI does not show status code.
I am using Alamofire for networking.

This red circle's supposed to be fail because the network response code returns 401.
However, it is shown as Success.
IMG_0397

This image is a detailed page of above image which returns status code as 401.
As image shown, Status Code displays as -.
2

Is there any parts that I am missing?
Thank you.

@kean
Copy link
Owner

kean commented Nov 12, 2021

Looks like a defect. Can you share how you logs the network requests, please?

@jubakong
Copy link
Author

jubakong commented Nov 12, 2021

logs:

struct NetworkLoggerEventMonitor: EventMonitor {
  let logger: NetworkLogger
  
  func request(_ request: Request, didCreateTask task: URLSessionTask) {
    logger.logTaskCreated(task)
  }
  
  func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
    logger.logDataTask(dataTask, didReceive: data)
  }
  
  func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
    logger.logTask(task, didFinishCollecting: metrics)
  }
  
  func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
    logger.logTask(task, didCompleteWithError: error)
  }
}

class APIManager {
  
  let logger = NetworkLogger()
  
  static let shared = APIManager()
  let manager: Alamofire.Session
  
  init() {
    let configure = URLSessionConfiguration.default
    configure.timeoutIntervalForRequest = 40
    configure.timeoutIntervalForResource = 40
    manager = Alamofire.Session(configuration: configure, eventMonitors: [NetworkLoggerEventMonitor(logger: logger)])
  }
}

I am using Alamofire + RxSwift for getting return value as Single

request:

  func request<T: Codable>(encoding: ParameterEncoding = JSONEncoding.default) -> Single<T> {
    return Single<T>.create { observer in
      let request = manager.request(
        endPoint,
        method: method,
        parameters: self.parameters,
        encoding: encoding,
        headers: headerAuthorization
      )
      
      request
        .handleCodable { (response: ResponseContainer<T>) in
          guard let isReachable = NetworkReachabilityManager()?.isReachable,
                isReachable
          else {
            let error = NSError(
              domain: "NETWORK_REACHABILITY_DOMAIN",
              code: -99,
              message: "Network is invalid"
            )
            return observer(.failure(error))
          }
          
          if let data = response.data {
            observer(.success(data))
          }
        } failure: { error in
          observer(.failure(error))
        }
      return Disposables.create {
        request.cancel()
      }
    }
  }

@kean
Copy link
Owner

kean commented Nov 13, 2021

Looks like this issue is specific to the Alamofire.EventMonitor. Unlike Pulse.URLSessionProxyDelegate, it doesn't have the following callback that provides a URLResponse:

public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
    ...    
}

I missed it when I wrote an example of EventMonitor.

Fortunately, it's not required. I'm going to ship a fix in today's release.

kean added a commit that referenced this issue Nov 13, 2021
@kean kean closed this as completed in 4a97899 Nov 13, 2021
@kean
Copy link
Owner

kean commented Nov 13, 2021

Fixed in 0.20.0

@jubakong
Copy link
Author

Now, it's working great!

@kean kean added the bug Something isn't working label Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants