diff --git a/lib/src/folksonomy.dart b/lib/src/folksonomy.dart index af701563da..92120c5c3e 100644 --- a/lib/src/folksonomy.dart +++ b/lib/src/folksonomy.dart @@ -169,7 +169,11 @@ class FolksonomyAPIClient { ), uriHelper: uriHelper, ); - _checkResponse(response); + // may return 404 (and "null") when not found. + _checkResponse( + response, + authorizedStatus: [200, 404], + ); if (response.body == 'null') { // not found return null; @@ -367,8 +371,11 @@ Future 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 authorizedStatus = const [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}'); }