CheckTimeout checks if the request context has timed out or cancelled and returns wrapped error.
(ctx context.Context)
| 30 | // CheckTimeout checks if the request context has timed out or cancelled and returns |
| 31 | // wrapped error. |
| 32 | func CheckTimeout(ctx context.Context) errctx.Error { |
| 33 | select { |
| 34 | case <-ctx.Done(): |
| 35 | d := RequestDuration(ctx) |
| 36 | |
| 37 | err := ctx.Err() |
| 38 | switch err { |
| 39 | case context.Canceled: |
| 40 | return newRequestCancelledError(d) |
| 41 | case context.DeadlineExceeded: |
| 42 | return newRequestTimeoutError(d) |
| 43 | default: |
| 44 | return errctx.Wrap(err) |
| 45 | } |
| 46 | default: |
| 47 | return nil |
| 48 | } |
| 49 | } |