Return 401 for Login Errors (#2312)

Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
Daniel Valdivia
2022-09-15 13:33:53 -07:00
committed by GitHub
parent 41671b4f25
commit 4ac6ecb558
3 changed files with 40 additions and 29 deletions

View File

@@ -81,6 +81,12 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *models.Error {
var exists bool
if len(err) > 0 {
if err1, exists = err[0].(error); exists {
var lastError error
if len(err) > 1 {
if err2, lastExists := err[1].(error); lastExists {
lastError = err2
}
}
if err1.Error() == ErrForbidden.Error() {
errorCode = 403
}
@@ -95,6 +101,11 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *models.Error {
errorCode = 401
errorMessage = ErrInvalidLogin.Error()
}
// If the last error is ErrInvalidLogin, this is a login failure
if errors.Is(lastError, ErrInvalidLogin) {
errorCode = 401
errorMessage = err1.Error()
}
if strings.Contains(err1.Error(), ErrLoginNotAllowed.Error()) {
errorCode = 400
errorMessage = ErrLoginNotAllowed.Error()