Skip to content

Commit

Permalink
fix: discord http error code handling
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Oct 9, 2024
1 parent 9a071bd commit cdc1305
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/discord/modules/userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (g *UserInfo) planUsers(ctx context.Context, roles types.Roles) (types.User
var dest []*userRoleMapping
if err := stmt.QueryContext(ctx, g.db, &dest); err != nil {
if !errors.Is(err, qrm.ErrNoRows) {
return users, logs, err
return users, logs, fmt.Errorf("failed to get user info from database. %w", err)
}
}

Expand All @@ -280,7 +280,7 @@ func (g *UserInfo) planUsers(ctx context.Context, roles types.Roles) (types.User
member, err := g.discord.Member(g.guild.ID, discord.UserID(externalId))
if err != nil {
if restErr, ok := err.(*httputil.HTTPError); ok {
if restErr.Code == http.StatusNotFound {
if restErr.Status == http.StatusNotFound {
// Add log about employee not being on discord
logs = append(logs, discord.Embed{
Title: fmt.Sprintf("UserInfo: Employee not found on Discord: %s %s", u.Firstname, u.Lastname),
Expand All @@ -292,7 +292,7 @@ func (g *UserInfo) planUsers(ctx context.Context, roles types.Roles) (types.User
}
}

errs = multierr.Append(errs, err)
errs = multierr.Append(errs, fmt.Errorf("discord API returned an error. %w", err))
continue
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/discord/types/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (p *Plan) applyUsers(dc *state.State) error {

for _, role := range user.Roles.ToRemove {
if err := dc.RemoveRole(p.GuildID, user.ID, role.ID, api.AuditLogReason(role.Module)); err != nil {
errs = multierr.Append(errs, fmt.Errorf("failed to remove user %s from role %s (%s). %w", user.ID, role.ID, role.Name, err))
errs = multierr.Append(errs, fmt.Errorf("failed to remove user %s from role %s (%s). %w", user.ID, role.Name, role.ID, err))
continue
}
}
Expand All @@ -98,7 +98,7 @@ func (p *Plan) applyUsers(dc *state.State) error {
if err := dc.AddRole(p.GuildID, user.ID, role.ID, api.AddRoleData{
AuditLogReason: api.AuditLogReason(role.Module),
}); err != nil {
errs = multierr.Append(errs, fmt.Errorf("failed to add user %s to role %s (%s). %w", user.ID, role.ID, role.Name, err))
errs = multierr.Append(errs, fmt.Errorf("failed to add user %s to role %s (%s). %w", user.ID, role.Name, role.ID, err))
continue
}
}
Expand Down

0 comments on commit cdc1305

Please sign in to comment.