fromResponse static method
Parse an error response from the PowerSync service
Implementation
static SyncResponseException fromResponse(http.Response response) {
try {
final body = response.body;
final decoded = convert.jsonDecode(body);
final details = _stringOrFirst(decoded['error']?['details']) ?? body;
final message = '${response.reasonPhrase ?? "Request failed"}: $details';
return SyncResponseException(response.statusCode, message);
} on FormatException catch (_) {
return SyncResponseException(
response.statusCode,
response.reasonPhrase ?? "Request failed",
);
} on Error catch (_) {
return SyncResponseException(
response.statusCode,
response.reasonPhrase ?? "Request failed",
);
}
}