mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-28 06:00:41 +00:00
* Post-release feedback on client reset (#1372) * Using error.name instead
This commit is contained in:
parent
1de8fbbf39
commit
e81d8589ae
@ -5,10 +5,12 @@ X.Y.Z Release notes
|
|||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
* Better support for React Native 0.49 for iOS (#1431).
|
* 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).
|
* 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
|
### Internal
|
||||||
* None.
|
* None.
|
||||||
|
@ -309,7 +309,7 @@ Realm.defaultPath;
|
|||||||
* - `user` - A `User` object obtained by calling `Realm.Sync.User.login`
|
* - `user` - A `User` object obtained by calling `Realm.Sync.User.login`
|
||||||
* - `url` - A `string` which contains a valid Realm Sync url
|
* - `url` - A `string` which contains a valid Realm Sync url
|
||||||
* - `error` - A callback function which is called in error situations.
|
* - `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`.
|
* `category`, and `code`.
|
||||||
* - `validate_ssl` - Indicating if SSL certificates must be validated
|
* - `validate_ssl` - Indicating if SSL certificates must be validated
|
||||||
* - `ssl_trust_certificate_path` - A path where to find trusted SSL certificates
|
* - `ssl_trust_certificate_path` - A path where to find trusted SSL certificates
|
||||||
|
@ -70,7 +70,7 @@ class Sync {
|
|||||||
* {
|
* {
|
||||||
* const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
|
* const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
|
||||||
* config.sync.error = (sender, error) => {
|
* config.sync.error = (sender, error) => {
|
||||||
* if (error.code === 7) { // 7 -> client reset
|
* if (error.name === 'ClientReset') {
|
||||||
* Realm.Sync.initiateClientReset(original_path);
|
* Realm.Sync.initiateClientReset(original_path);
|
||||||
* // copy required objects from Realm at error.config.path
|
* // copy required objects from Realm at error.config.path
|
||||||
* }
|
* }
|
||||||
|
5
lib/index.d.ts
vendored
5
lib/index.d.ts
vendored
@ -346,9 +346,10 @@ declare namespace Realm.Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface SyncError {
|
interface SyncError {
|
||||||
|
name: string;
|
||||||
message: string;
|
message: string;
|
||||||
isFatal: boolean
|
isFatal: boolean;
|
||||||
category?: string
|
category?: string;
|
||||||
code: number;
|
code: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,22 +228,22 @@ public:
|
|||||||
void operator()(std::shared_ptr<SyncSession> session, SyncError error) {
|
void operator()(std::shared_ptr<SyncSession> session, SyncError error) {
|
||||||
HANDLESCOPE
|
HANDLESCOPE
|
||||||
|
|
||||||
|
std::string name = "Error";
|
||||||
auto error_object = Object<T>::create_empty(m_ctx);
|
auto error_object = Object<T>::create_empty(m_ctx);
|
||||||
|
|
||||||
auto error_code = error.error_code.value();
|
|
||||||
if (error.is_client_reset_requested()) {
|
if (error.is_client_reset_requested()) {
|
||||||
error_code = 7; // FIXME: define a proper constant
|
|
||||||
|
|
||||||
auto config_object = Object<T>::create_empty(m_ctx);
|
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, "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, config_object, "readOnly", Value<T>::from_boolean(m_ctx, true));
|
||||||
Object<T>::set_property(m_ctx, error_object, "config", config_object);
|
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, "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, "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, "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);
|
auto user_info = Object<T>::create_empty(m_ctx);
|
||||||
for (auto& kvp : error.user_info) {
|
for (auto& kvp : error.user_info) {
|
||||||
|
@ -742,13 +742,13 @@ module.exports = {
|
|||||||
const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
|
const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
|
||||||
config.sync.error = (sender, error) => {
|
config.sync.error = (sender, error) => {
|
||||||
try {
|
try {
|
||||||
TestCase.assertEqual(error.code, 7); // 7 -> client reset
|
TestCase.assertEqual(error.name, 'ClientReset');
|
||||||
TestCase.assertDefined(error.config);
|
TestCase.assertDefined(error.config);
|
||||||
TestCase.assertNotEqual(error.config.path, '');
|
TestCase.assertNotEqual(error.config.path, '');
|
||||||
const original_path = realm.path;
|
const path = realm.path;
|
||||||
realm.close();
|
realm.close();
|
||||||
Realm.Sync.initiateClientReset(original_path);
|
Realm.Sync.initiateClientReset(path);
|
||||||
// copy required objects from Realm at error.config.path
|
// open Realm with error.config, and copy required objects a Realm at `path`
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user