Skip to content

Commit

Permalink
fix: Handle error
Browse files Browse the repository at this point in the history
Signed-off-by: sawadashota <shota@sslife.tech>
  • Loading branch information
sawadashota committed Jul 29, 2022
1 parent 0ae3658 commit 1ad6caa
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions persistence/sql/persister_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,15 @@ func (p *Persister) deleteSessionBySignature(ctx context.Context, signature stri
signature = p.hashSignature(signature, table)

/* #nosec G201 table is static */
if err := p.Connection(ctx).
RawQuery(fmt.Sprintf("DELETE FROM %s WHERE signature=?", OAuth2RequestSQL{Table: table}.TableName()), signature).
Exec(); errors.Is(err, sql.ErrNoRows) {
err := sqlcon.HandleError(
p.Connection(ctx).
RawQuery(fmt.Sprintf("DELETE FROM %s WHERE signature=?", OAuth2RequestSQL{Table: table}.TableName()), signature).
Exec())
if errors.Is(err, sqlcon.ErrNoRows) {
return errorsx.WithStack(fosite.ErrNotFound)
} else if err := sqlcon.HandleError(err); err != nil {
if errors.Is(err, sqlcon.ErrConcurrentUpdate) {
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
} else if strings.Contains(err.Error(), "Error 1213") { // InnoDB Deadlock?
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
}
} else if errors.Is(err, sqlcon.ErrConcurrentUpdate) {
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
} else if err != nil {
return err
}
return nil
Expand Down

0 comments on commit 1ad6caa

Please sign in to comment.