fix: invalid error unwrap for the httperror (#2753)

Signed-off-by: saltbo <saltbo@foxmail.com>
This commit is contained in:
Ambor
2023-03-31 12:23:37 +05:30
committed by GitHub
parent 715ef8267e
commit 77d4745242
2 changed files with 42 additions and 4 deletions
+6 -4
View File
@@ -17,6 +17,7 @@ limitations under the License.
package error
import (
"errors"
"fmt"
"io"
"net/http"
@@ -106,8 +107,8 @@ func (err Error) Description() string {
func GetHTTPError(err error) (int, string) {
var msg string
var code int
fe, ok := err.(Error)
if ok {
var fe Error
if errors.As(err, &fe) {
code = fe.HTTPStatus()
msg = fe.Message
} else {
@@ -118,10 +119,11 @@ func GetHTTPError(err error) (int, string) {
}
func IsNotFound(err error) bool {
fe, ok := err.(Error)
if !ok {
var fe Error
if !errors.As(err, &fe) {
return false
}
return fe.Code == ErrorNotFound
}