Complete the code to catch exceptions during a network call.
try { final response = await http.get(Uri.parse('https://api.example.com/data')); print(response.body); } catch ([1]) { print('Error occurred'); }
The catch block catches exceptions of type Exception during network calls.
Complete the code to check if the HTTP response status code indicates success.
if (response.statusCode [1] 200) { print('Success'); } else { print('Failed'); }
The status code 200 means the request was successful, so we check if it equals 200.
Fix the error in the catch block to print the error message.
try { final response = await http.get(Uri.parse('https://api.example.com/data')); } catch (e) { print([1]); }
Using e.toString() converts the error object to a readable string message.
Fill both blanks to retry the network call only if the status code is 500.
if (response.statusCode [1] 500) { await Future.delayed(Duration(seconds: [2])); // retry logic here }
We check if status code equals 500 and wait 3 seconds before retrying.
Fill all three blanks to create a map of error messages for different status codes.
final errorMessages = {
400: '[1]',
401: '[2]',
404: '[3]'
};These are standard HTTP error messages for the given status codes.
