Skip to content

Commit

Permalink
fix: folksonomy getProductTag may return 404 (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki authored Feb 13, 2024
1 parent e18080b commit 990cc67
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/src/folksonomy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ class FolksonomyAPIClient {
),
uriHelper: uriHelper,
);
_checkResponse(response);
// may return 404 (and "null") when not found.
_checkResponse(
response,
authorizedStatus: <int>[200, 404],
);
if (response.body == 'null') {
// not found
return null;
Expand Down Expand Up @@ -367,8 +371,11 @@ Future<void> deleteProductTag({
}

/// Throws a detailed exception if relevant. Does nothing if [response] is OK.
static void _checkResponse(final Response response) {
if (response.statusCode != 200) {
static void _checkResponse(
final Response response, {
final List<int> authorizedStatus = const <int>[200],
}) {
if (!authorizedStatus.contains(response.statusCode)) {
// TODO have a look at ValidationError in https://api.folksonomy.openfoodfacts.org/docs
throw Exception('Wrong status code: ${response.statusCode}');
}
Expand Down

0 comments on commit 990cc67

Please sign in to comment.