Skip to content

Commit 810b748

Browse files
authored
chore: add status code to error message (#11)
* chore: add status code to error message * chore: add project resource docs
1 parent b703456 commit 810b748

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

docs/resources/project.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "supabase_project Resource - terraform-provider-supabase"
4+
subcategory: ""
5+
description: |-
6+
Project resource
7+
---
8+
9+
# supabase_project (Resource)
10+
11+
Project resource
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "supabase_project" "test" {
17+
organization_id = "continued-brown-smelt"
18+
name = "foo"
19+
database_password = "bar"
20+
region = "us-east-1"
21+
}
22+
```
23+
24+
<!-- schema generated by tfplugindocs -->
25+
## Schema
26+
27+
### Required
28+
29+
- `database_password` (String, Sensitive) Password for the project database
30+
- `name` (String) Name of the project
31+
- `organization_id` (String) Reference to the organization
32+
- `region` (String) Region where the project is located
33+
34+
### Read-Only
35+
36+
- `id` (String) Project identifier

internal/provider/branch_data_source.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ func (d *BranchDataSource) Read(ctx context.Context, req datasource.ReadRequest,
106106
// provider client data and make a call using it.
107107
httpResp, err := d.client.GetBranchesWithResponse(ctx, projectRef.ValueString())
108108
if err != nil {
109-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read branch, got error: %s", err))
109+
msg := fmt.Sprintf("Unable to read branch, got error: %s", err)
110+
resp.Diagnostics.AddError("Client Error", msg)
110111
return
111112
}
112113
if httpResp.JSON200 == nil {
113-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read branch, got error: %s", httpResp.Body))
114+
msg := fmt.Sprintf("Unable to read branch, got status %d: %s", httpResp.StatusCode(), httpResp.Body)
115+
resp.Diagnostics.AddError("Client Error", msg)
114116
return
115117
}
116118

internal/provider/project_resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func (r *ProjectResource) Update(ctx context.Context, req resource.UpdateRequest
152152
return
153153
}
154154

155+
// TODO: allow api to update project resource
155156
msg := fmt.Sprintf("Update is not supported for project resource: %s", data.Id.ValueString())
156157
resp.Diagnostics.Append(diag.NewErrorDiagnostic("Client Error", msg))
157158
}

internal/provider/settings_resource.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,21 @@ func readApiConfig(ctx context.Context, data *SettingsResourceModel, client *api
219219
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
220220
}
221221
// Deleted project is an orphan resource, not returning error so it can be destroyed.
222-
if httpResp.StatusCode() == http.StatusNotFound {
222+
switch httpResp.StatusCode() {
223+
case http.StatusNotFound, http.StatusNotAcceptable:
223224
return nil
225+
default:
226+
break
224227
}
225228
if httpResp.JSON200 == nil {
226-
msg := fmt.Sprintf("Unable to read api settings, got error: %s", httpResp.Body)
229+
msg := fmt.Sprintf("Unable to read api settings, got status %d: %s", httpResp.StatusCode(), httpResp.Body)
227230
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
228231
}
229232

230233
httpResp.JSON200.JwtSecret = nil
231234
value, err := json.Marshal(*httpResp.JSON200)
232235
if err != nil {
233-
msg := fmt.Sprintf("Unable to read api settings, got error: %s", err)
236+
msg := fmt.Sprintf("Unable to read api settings, got marshal error: %s", err)
234237
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
235238
}
236239

@@ -250,13 +253,13 @@ func updateApiConfig(ctx context.Context, data *SettingsResourceModel, client *a
250253
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
251254
}
252255
if httpResp.JSON200 == nil {
253-
msg := fmt.Sprintf("Unable to update api settings, got error: %s", httpResp.Body)
256+
msg := fmt.Sprintf("Unable to update api settings, got status %d: %s", httpResp.StatusCode(), httpResp.Body)
254257
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
255258
}
256259

257260
value, err := json.Marshal(*httpResp.JSON200)
258261
if err != nil {
259-
msg := fmt.Sprintf("Unable to update api settings, got error: %s", err)
262+
msg := fmt.Sprintf("Unable to update api settings, got marshal error: %s", err)
260263
return diag.Diagnostics{diag.NewErrorDiagnostic("Client Error", msg)}
261264
}
262265

0 commit comments

Comments
 (0)