httpx icon indicating copy to clipboard operation
httpx copied to clipboard

Cannot catch error when using OnResult

Open anhnmt opened this issue 2 years ago • 0 comments

I'm using httpx as a library and i'm not able to catch individual error for each target using OnResult function. Please help me

in the example below i'm using httpx v1.3.0, target that i use: localhost I used the code below to try to catch the error but failed, the log is not printed at all

		OnResult: func(r runner.Result) {
			l := log.Info().
				Str("url", r.Input)

			if r.FinalURL != "" {
				l.Str("finalURL", r.FinalURL)
			}

			if r.Error != "" {
				l.Str("error", r.Error)
			}

			if r.TLSData != nil {
				if !r.TLSData.NotAfter.IsZero() {
					l.Str("tlsNotAfter", r.TLSData.NotAfter.Format(time.RFC3339))
				}
			}

			l.Str("scheme", r.Scheme).
				Int("statusCode", r.StatusCode).
				Str("responseTime", r.ResponseTime).
				Bool("failed", r.Failed).
				Msg("Ping url")
		},

anhnmt avatar May 02 '23 03:05 anhnmt