summaryrefslogtreecommitdiff
path: root/internal/federation/dereferencing/error.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-03-06 09:38:43 +0000
committerLibravatar GitHub <noreply@github.com>2023-03-06 10:38:43 +0100
commitd8d5818b47009f28433a7e96bcce8d116c8a9769 (patch)
treea93b7fe7deaa286fde5eab450b4cb30fbe7566dd /internal/federation/dereferencing/error.go
parent[feature] Add support for profile fields (#1483) (diff)
downloadgotosocial-d8d5818b47009f28433a7e96bcce8d116c8a9769.tar.xz
[bugfix] internal server error on search not found (#1590)
* add error value wrapping, include status code / not found flags from transport errors, update error usages Signed-off-by: kim <grufwub@gmail.com> * add code commenting for gtserror functions Signed-off-by: kim <grufwub@gmail.com> --------- Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/federation/dereferencing/error.go')
-rw-r--r--internal/federation/dereferencing/error.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/internal/federation/dereferencing/error.go b/internal/federation/dereferencing/error.go
index 3ba357f7a..530c72b32 100644
--- a/internal/federation/dereferencing/error.go
+++ b/internal/federation/dereferencing/error.go
@@ -19,10 +19,10 @@
package dereferencing
import (
- "errors"
"fmt"
+ "net/http"
- "github.com/superseriousbusiness/gotosocial/internal/transport"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
)
// ErrDB denotes that a proper error has occurred when doing
@@ -96,22 +96,21 @@ func newErrOther(err error) error {
}
func wrapDerefError(derefErr error, fluff string) error {
- var (
- err error
- errWrongType *ErrWrongType
- )
-
+ // Wrap with fluff.
+ err := derefErr
if fluff != "" {
err = fmt.Errorf("%s: %w", fluff, derefErr)
}
- switch {
- case errors.Is(derefErr, transport.ErrGone):
- err = NewErrNotRetrievable(err)
- case errors.As(derefErr, &errWrongType):
- err = newErrWrongType(err)
- default:
- err = newErrTransportError(err)
+ // Check for unretrievable HTTP status code errors.
+ if code := gtserror.StatusCode(derefErr); // nocollapse
+ code == http.StatusGone || code == http.StatusNotFound {
+ return NewErrNotRetrievable(err)
+ }
+
+ // Check for other untrievable errors.
+ if gtserror.NotFound(derefErr) {
+ return NewErrNotRetrievable(err)
}
return err