Skip to content

Commit

Permalink
refactor: enhance error handling and response processing in Quickbase…
Browse files Browse the repository at this point in the history
…Client (#2)

- Modify the QueryRecords method to handle different types of errors more explicitly, including client errors, server errors, and generic failures.
- Introduce additional checks for empty data in the QueryRecords method, returning a specific 'NotFound' error if no records are found.
- Update InsertRecords and UpdateRecords methods for consistent error handling and response processing.
- Improve overall readability and maintainability of the QuickbaseClient class.

NOTE: These changes may affect how client errors and empty query results are handled, requiring adjustments in client code.
  • Loading branch information
ducksoop committed Jan 23, 2024
1 parent e8db396 commit 5fe38e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion QuickbaseNet/Services/QuickbaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public async Task<QuickbaseResult<QuickbaseQueryResponse>> QueryRecords(Quickbas
if (response.IsSuccessStatusCode)
{
var queryResponse = JsonConvert.DeserializeObject<QuickbaseQueryResponse>(jsonResponse);
return QuickbaseResult.Success(queryResponse);

// Check if data is null or empty
return queryResponse.Data.Count == 0
? QuickbaseResult.Failure<QuickbaseQueryResponse>(QuickbaseError.NotFound("QuickbaseNet.Failure",
"No records found", $"The query did not find any records matching that criteria"))
: QuickbaseResult.Success(queryResponse);
}

var errorResponse = JsonConvert.DeserializeObject<QuickbaseErrorResponse>(jsonResponse);
Expand All @@ -52,6 +57,7 @@ public async Task<QuickbaseResult<QuickbaseQueryResponse>> QueryRecords(Quickbas
return QuickbaseResult.Failure<QuickbaseQueryResponse>(QuickbaseError.ServerError("QuickbaseNet.ServerError", errorResponse.Message, errorResponse.Description));
}

// Return generic failure
return QuickbaseResult.Failure<QuickbaseQueryResponse>(QuickbaseError.Failure("QuickbaseNet.Failure", errorResponse.Message, errorResponse.Description));
}

Expand Down

0 comments on commit 5fe38e5

Please sign in to comment.