resolve method
Gets the data from the remote source and returns the raw data. The returned string will be saved in the cache and decoded using fromJson.
Implementation
@override
Future<String> resolve() async {
try {
final request = RepositoryHttpRequest(url: endpoint);
final response = await client.get(request: request);
/// If the endpoint returns a 200, add the data to the stream
/// and cache it
if (successfulCondition(response.statusCode, response.body)) {
final result = response.body;
return result;
} else {
Repository.logger(
'Repository($name): Failed to resolve [$endpoint]. '
'status code: ${response.statusCode}',
);
await onErrorStatusCode(response.statusCode);
throw UnexpectedStatusCodeException(
sent: request,
received: response,
);
}
} catch (exception) {
/// if the user is offline, the request will fail.
/// if [onSocketException] is not null, we call it.
/// if [onSocketException] is null, we rethrow the exception.
Repository.logger(
'Repository($name): throws [${exception.runtimeType}].',
level: RepositoryLoggingLevel.warning,
);
if (exception is Exception) {
await onSocketException(exception);
}
rethrow;
}
}