Post-release feedback on client reset (#1372) (#1459)

* Post-release feedback on client reset (#1372)
* Using error.name instead
This commit is contained in:
Kenneth Geisshirt 2017-11-06 13:51:33 +01:00 committed by GitHub
parent 1de8fbbf39
commit e81d8589ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 15 deletions

View File

@ -5,10 +5,12 @@ X.Y.Z Release notes
### Enhancements
* Better support for React Native 0.49 for iOS (#1431).
* Added property `name` to `error` in `Sync.error` callback.
* Sync error handler provides also a property called `name`; `code` is not changed.
### Bug fixea
### Bug fixed
* Fixed missing Realm constructor in while debugging React Native apps (#1436).
* Remove argument in documentation of `Realm.Sync.Adapter.realmAtPath()`.
* Removed argument in documentation of `Realm.Sync.Adapter.realmAtPath()`.
### Internal
* None.

View File

@ -309,7 +309,7 @@ Realm.defaultPath;
* - `user` - A `User` object obtained by calling `Realm.Sync.User.login`
* - `url` - A `string` which contains a valid Realm Sync url
* - `error` - A callback function which is called in error situations.
* The `error` callback can take up to four optional arguments: `message`, `isFatal`,
* The `error` callback can take up to five optional arguments: `name`, `message`, `isFatal`,
* `category`, and `code`.
* - `validate_ssl` - Indicating if SSL certificates must be validated
* - `ssl_trust_certificate_path` - A path where to find trusted SSL certificates

View File

@ -70,7 +70,7 @@ class Sync {
* {
* const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
* config.sync.error = (sender, error) => {
* if (error.code === 7) { // 7 -> client reset
* if (error.name === 'ClientReset') {
* Realm.Sync.initiateClientReset(original_path);
* // copy required objects from Realm at error.config.path
* }

5
lib/index.d.ts vendored
View File

@ -346,9 +346,10 @@ declare namespace Realm.Sync {
}
interface SyncError {
name: string;
message: string;
isFatal: boolean
category?: string
isFatal: boolean;
category?: string;
code: number;
}

View File

@ -228,22 +228,22 @@ public:
void operator()(std::shared_ptr<SyncSession> session, SyncError error) {
HANDLESCOPE
std::string name = "Error";
auto error_object = Object<T>::create_empty(m_ctx);
auto error_code = error.error_code.value();
if (error.is_client_reset_requested()) {
error_code = 7; // FIXME: define a proper constant
auto config_object = Object<T>::create_empty(m_ctx);
Object<T>::set_property(m_ctx, config_object, "path", Value<T>::from_string(m_ctx, error.user_info[SyncError::c_recovery_file_path_key]));
Object<T>::set_property(m_ctx, config_object, "readOnly", Value<T>::from_boolean(m_ctx, true));
Object<T>::set_property(m_ctx, error_object, "config", config_object);
name = "ClientReset";
}
Object<T>::set_property(m_ctx, error_object, "name", Value<T>::from_string(m_ctx, name));
Object<T>::set_property(m_ctx, error_object, "message", Value<T>::from_string(m_ctx, error.message));
Object<T>::set_property(m_ctx, error_object, "isFatal", Value<T>::from_boolean(m_ctx, error.is_fatal));
Object<T>::set_property(m_ctx, error_object, "category", Value<T>::from_string(m_ctx, error.error_code.category().name()));
Object<T>::set_property(m_ctx, error_object, "code", Value<T>::from_number(m_ctx, error_code));
Object<T>::set_property(m_ctx, error_object, "code", Value<T>::from_number(m_ctx, error.error_code.value()));
auto user_info = Object<T>::create_empty(m_ctx);
for (auto& kvp : error.user_info) {

View File

@ -742,13 +742,13 @@ module.exports = {
const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
config.sync.error = (sender, error) => {
try {
TestCase.assertEqual(error.code, 7); // 7 -> client reset
TestCase.assertEqual(error.name, 'ClientReset');
TestCase.assertDefined(error.config);
TestCase.assertNotEqual(error.config.path, '');
const original_path = realm.path;
const path = realm.path;
realm.close();
Realm.Sync.initiateClientReset(original_path);
// copy required objects from Realm at error.config.path
Realm.Sync.initiateClientReset(path);
// open Realm with error.config, and copy required objects a Realm at `path`
resolve();
}
catch (e) {