mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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>
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user