implemented extended gql errors
This commit is contained in:
parent
20f95b8ea4
commit
024948b8ff
25
internal/errors.go
Normal file
25
internal/errors.go
Normal file
@ -0,0 +1,25 @@
|
||||
package s3browser
|
||||
|
||||
import "fmt"
|
||||
|
||||
type extendedError struct {
|
||||
Message string
|
||||
Code string
|
||||
}
|
||||
|
||||
func (err *extendedError) Error() string {
|
||||
return err.Message
|
||||
}
|
||||
|
||||
func (err *extendedError) Extensions() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"code": err.Code,
|
||||
}
|
||||
}
|
||||
|
||||
func extendError(code, format string, a ...interface{}) *extendedError {
|
||||
return &extendedError{
|
||||
Message: fmt.Sprintf(format, a...),
|
||||
Code: code,
|
||||
}
|
||||
}
|
@ -114,12 +114,12 @@ func isAuth(ctx context.Context) (bool, error) {
|
||||
token, ok := ctx.Value("jwt").(*jwt.Token)
|
||||
|
||||
if !ok {
|
||||
return false, fmt.Errorf("Unauthorized")
|
||||
return false, extendError("UNAUTHORIZED", "Unauthorized")
|
||||
}
|
||||
|
||||
if token.Valid {
|
||||
return true, nil
|
||||
} else {
|
||||
return false, fmt.Errorf("Unauthorized")
|
||||
return false, extendError("UNAUTHORIZED", "Unauthorized")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user