Skip to content

Commit

Permalink
chore: factor out isTimeoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Apr 13, 2023
1 parent 7a7a18b commit df95327
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion selfservice/hook/web_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (e *WebHook) execute(ctx context.Context, data *templateContext) error {

resp, err := httpClient.Do(req)
if err != nil {
if te := interface{ Timeout() bool }(nil); errors.As(err, &te) && te.Timeout() || errors.Is(err, context.DeadlineExceeded) {
if isTimeoutError(err) {
return herodot.DefaultError{
CodeField: http.StatusGatewayTimeout,
StatusField: http.StatusText(http.StatusGatewayTimeout),
Expand Down Expand Up @@ -487,3 +487,8 @@ func parseWebhookResponse(resp *http.Response, id *identity.Identity) (err error

return nil
}

func isTimeoutError(err error) bool {
var te interface{ Timeout() bool }
return errors.As(err, &te) && te.Timeout() || errors.Is(err, context.DeadlineExceeded)
}

0 comments on commit df95327

Please sign in to comment.