Chapter 12, API errors are not handled correctly. I guess!

The current implementation of ModelConverter.decodeJson() in Chapter 12 uses the following trick to catch API errors, assuming that response.isSuccessful is true

if (jsonMap['status'] != null) {
  return response.copyWith(
   body: Faileur(Exception(jsonMap)) as BodyType,
  );
}

But actually, when we send invalid request, for example with wrong api_key, the response body is indeed as assumed jsonMap['status'] != null but with status_code: 401 and response.isSuccessful = false, thus the response is not intercepted by our ModelConverter but by the errorConverter which we don’t use, and also the implementation of _buildRecipeLoader doesn’t handle that case.

Thanks for reporting this.
It’s been fixed and will be released soon in an upcoming release.

1 Like

Actually I did check the updated code here https://github.com/raywenderlich/flta-materials/tree/Chapter-12-update but the bug seemed to be there so I thought I should report it.