fix: make discord login work if no user exists

This commit is contained in:
Sam 2023-03-11 16:49:07 +01:00
parent 8c187d0fb3
commit 75f628c722
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
2 changed files with 12 additions and 0 deletions

View File

@ -102,6 +102,10 @@ func (db *DB) DiscordUser(ctx context.Context, discordID string) (u User, err er
var id xid.ID var id xid.ID
err = db.QueryRow(ctx, sql, args...).Scan(&id) err = db.QueryRow(ctx, sql, args...).Scan(&id)
if err != nil { if err != nil {
if errors.Cause(err) == pgx.ErrNoRows {
return u, ErrUserNotFound
}
return u, errors.Wrap(err, "executing id query") return u, errors.Wrap(err, "executing id query")
} }

View File

@ -50,6 +50,14 @@ type APIError struct {
} }
func (e APIError) Error() string { func (e APIError) Error() string {
if e.Message == "" {
e.Message = errCodeMessages[e.Code]
}
if e.Details != "" {
return fmt.Sprintf("%s (code: %d) (%s)", e.Message, e.Code, e.Details)
}
return fmt.Sprintf("%s (code: %d)", e.Message, e.Code) return fmt.Sprintf("%s (code: %d)", e.Message, e.Code)
} }