Skip to content

Commit

Permalink
stream & error
Browse files Browse the repository at this point in the history
  • Loading branch information
fritx committed Aug 9, 2024
1 parent ba96e2b commit e37d25a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions util/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package util

import "errors"

func IsErrorLike(left, right error) bool {
return left == nil && right == nil ||
left != nil && right != nil && left.Error() == right.Error() ||
errors.Is(left, right)
}
9 changes: 8 additions & 1 deletion util/http_handler_stream.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"context"
"errors"
"net/http"
"time"
Expand Down Expand Up @@ -36,9 +37,15 @@ func StreamHandlerWrap(
}); err != nil {
if errors.Is(err, ErrHandledAndBreak) {
HttpLog(r, start, 200, err)
} else if errors.Is(err, StreamEof) {
// } else if errors.Is(err, StreamEof) {
} else if IsErrorLike(err, StreamEof) {
// noop
HttpLog(r, start, 200, nil)
} else if errors.Is(err, context.DeadlineExceeded) {
// ignore
w.Write([]byte("..."))
flusher.Flush()
HttpLog(r, start, 200, nil)
} else {
if e, ok := err.(IStatusError); ok && e.Status() < 500 {
SendErrText(w, err)
Expand Down

0 comments on commit e37d25a

Please sign in to comment.