Skip to content

Commit

Permalink
feat: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
acch committed Sep 27, 2024
1 parent 71abdfe commit 79a6b2d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/provider/organization_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ func (d *organizationDataSource) Read(ctx context.Context, req datasource.ReadRe
if err != nil {
tflog.Error(ctx, "Error", map[string]any{"status": r.Status})

msg := err.Error()
if r.StatusCode == 404 {
var msg string
switch r.StatusCode {
case 404:
msg = fmt.Sprintf("Organization with name %s not found.", data.Name.String())
default:
msg = fmt.Sprintf("Unknow error %s.", err.Error())
}
resp.Diagnostics.AddError("Unable to read Forgejo organization", msg)
resp.Diagnostics.AddError("Unable to get organization by name", msg)

return
}
Expand Down

0 comments on commit 79a6b2d

Please sign in to comment.