From 79a6b2df66b25271c587f9a77ec64c41c81fb6ac Mon Sep 17 00:00:00 2001 From: Achim Christ Date: Fri, 27 Sep 2024 16:59:02 +0000 Subject: [PATCH] feat: improve error handling --- internal/provider/organization_data_source.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/provider/organization_data_source.go b/internal/provider/organization_data_source.go index 8f18231..1eaeb58 100644 --- a/internal/provider/organization_data_source.go +++ b/internal/provider/organization_data_source.go @@ -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 }