|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | | - "strings" |
8 | 7 |
|
9 | 8 | "github.com/Masterminds/semver/v3" |
| 9 | + "google.golang.org/grpc/codes" |
10 | 10 | "google.golang.org/protobuf/types/known/wrapperspb" |
11 | 11 |
|
12 | 12 | "github.com/smartcontractkit/chainlink-deployments-framework/datastore" |
@@ -84,12 +84,17 @@ func (s *catalogAddressRefStore) get( |
84 | 84 | } |
85 | 85 |
|
86 | 86 | // Check for errors in the response |
87 | | - if response.Status != nil && !response.Status.Succeeded { |
88 | | - if strings.Contains(response.Status.GetError(), "No records found") { |
89 | | - return datastore.AddressRef{}, datastore.ErrAddressRefNotFound |
| 87 | + if statusErr := parseResponseStatus(response.Status); statusErr != nil { |
| 88 | + st, sterr := parseStatusError(statusErr) |
| 89 | + if sterr != nil { |
| 90 | + return datastore.AddressRef{}, sterr |
90 | 91 | } |
91 | 92 |
|
92 | | - return datastore.AddressRef{}, fmt.Errorf("request failed: %s", response.Status.Error) |
| 93 | + if st.Code() == codes.NotFound { |
| 94 | + return datastore.AddressRef{}, fmt.Errorf("%w: %s", datastore.ErrAddressRefNotFound, statusErr.Error()) |
| 95 | + } |
| 96 | + |
| 97 | + return datastore.AddressRef{}, fmt.Errorf("get address ref failed: %w", statusErr) |
93 | 98 | } |
94 | 99 |
|
95 | 100 | // Extract the address find response |
@@ -151,8 +156,8 @@ func (s *catalogAddressRefStore) Fetch(_ context.Context) ([]datastore.AddressRe |
151 | 156 | } |
152 | 157 |
|
153 | 158 | // Check for errors in the response |
154 | | - if response.Status != nil && !response.Status.Succeeded { |
155 | | - return nil, fmt.Errorf("request failed: %s", response.Status.Error) |
| 159 | + if err := parseResponseStatus(response.Status); err != nil { |
| 160 | + return nil, fmt.Errorf("fetch address refs failed: %w", err) |
156 | 161 | } |
157 | 162 |
|
158 | 163 | // Extract the address find response |
@@ -231,8 +236,8 @@ func (s *catalogAddressRefStore) Add(_ context.Context, record datastore.Address |
231 | 236 | } |
232 | 237 |
|
233 | 238 | // Check for errors in the edit response |
234 | | - if editResponse.Status != nil && !editResponse.Status.Succeeded { |
235 | | - return fmt.Errorf("edit request failed: %s", editResponse.Status.Error) |
| 239 | + if err := parseResponseStatus(editResponse.Status); err != nil { |
| 240 | + return fmt.Errorf("add address ref failed: %w", err) |
236 | 241 | } |
237 | 242 |
|
238 | 243 | // Extract the edit response to validate it |
@@ -278,8 +283,8 @@ func (s *catalogAddressRefStore) Upsert(_ context.Context, record datastore.Addr |
278 | 283 | } |
279 | 284 |
|
280 | 285 | // Check for errors in the response |
281 | | - if response.Status != nil && !response.Status.Succeeded { |
282 | | - return fmt.Errorf("request failed: %s", response.Status.Error) |
| 286 | + if err := parseResponseStatus(response.Status); err != nil { |
| 287 | + return fmt.Errorf("upsert address ref failed: %w", err) |
283 | 288 | } |
284 | 289 |
|
285 | 290 | // Extract the edit response to validate it |
@@ -338,8 +343,8 @@ func (s *catalogAddressRefStore) Update(ctx context.Context, record datastore.Ad |
338 | 343 | } |
339 | 344 |
|
340 | 345 | // Check for errors in the edit response |
341 | | - if editResponse.Status != nil && !editResponse.Status.Succeeded { |
342 | | - return fmt.Errorf("edit request failed: %s", editResponse.Status.Error) |
| 346 | + if err := parseResponseStatus(editResponse.Status); err != nil { |
| 347 | + return fmt.Errorf("update address ref failed: %w", err) |
343 | 348 | } |
344 | 349 |
|
345 | 350 | // Extract the edit response to validate it |
|
0 commit comments