Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 1df7951

Browse files
No error thrown when write fails #455
1 parent 91dec18 commit 1df7951

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[Firebase iOS SDK Changelog](https://firebase.google.com/support/release-notes/ios)
44
[Firebase Android SDK Changelog](https://firebase.google.com/support/release-notes/android)
55

6-
## 6.4.1 (2018, July 13)
6+
## 6.4.1 (2018, July 23)
77
[Fixes & Enhancements](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/milestone/64?closed=1)
88

99

src/firebase.android.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,10 +1703,14 @@ firebase.push = (path, val) => {
17031703
}
17041704

17051705
const pushInstance = firebase.instance.child(path).push();
1706-
pushInstance.setValue(firebase.toValue(val));
1707-
resolve({
1708-
key: pushInstance.getKey()
1706+
1707+
const onCompletionListener = new com.google.firebase.database.DatabaseReference.CompletionListener({
1708+
onComplete: (error: any /* com.google.firebase.database.DatabaseError */, dbRef: any /* com.google.firebase.database.DatabaseReference */) => {
1709+
error ? reject(error.getMessage()) : resolve({ key: pushInstance.getKey() });
1710+
}
17091711
});
1712+
1713+
pushInstance.setValue(firebase.toValue(val), onCompletionListener);
17101714
} catch (ex) {
17111715
console.log("Error in firebase.push: " + ex);
17121716
reject(ex);
@@ -1722,8 +1726,13 @@ firebase.setValue = (path, val) => {
17221726
return;
17231727
}
17241728

1725-
firebase.instance.child(path).setValue(firebase.toValue(val));
1726-
resolve();
1729+
const onCompletionListener = new com.google.firebase.database.DatabaseReference.CompletionListener({
1730+
onComplete: (error: any /* com.google.firebase.database.DatabaseError */, dbRef: any /* com.google.firebase.database.DatabaseReference */) => {
1731+
error ? reject(error.getMessage()) : resolve();
1732+
}
1733+
});
1734+
1735+
firebase.instance.child(path).setValue(firebase.toValue(val), onCompletionListener);
17271736
} catch (ex) {
17281737
console.log("Error in firebase.setValue: " + ex);
17291738
reject(ex);
@@ -1739,16 +1748,21 @@ firebase.update = (path, val) => {
17391748
return;
17401749
}
17411750

1751+
const onCompletionListener = new com.google.firebase.database.DatabaseReference.CompletionListener({
1752+
onComplete: (error: any /* com.google.firebase.database.DatabaseError */, dbRef: any /* com.google.firebase.database.DatabaseReference */) => {
1753+
error ? reject(error.getMessage()) : resolve();
1754+
}
1755+
});
1756+
17421757
if (typeof val === "object") {
1743-
firebase.instance.child(path).updateChildren(firebase.toHashMap(val));
1758+
firebase.instance.child(path).updateChildren(firebase.toHashMap(val), onCompletionListener);
17441759
} else {
17451760
const lastPartOfPath = path.lastIndexOf("/");
17461761
const pathPrefix = path.substring(0, lastPartOfPath);
17471762
const pathSuffix = path.substring(lastPartOfPath + 1);
17481763
const updateObject = '{"' + pathSuffix + '" : "' + val + '"}';
1749-
firebase.instance.child(pathPrefix).updateChildren(firebase.toHashMap(JSON.parse(updateObject)));
1764+
firebase.instance.child(pathPrefix).updateChildren(firebase.toHashMap(JSON.parse(updateObject)), onCompletionListener);
17501765
}
1751-
resolve();
17521766
} catch (ex) {
17531767
console.log("Error in firebase.update: " + ex);
17541768
reject(ex);
@@ -1879,8 +1893,14 @@ firebase.remove = path => {
18791893
reject("Run init() first!");
18801894
return;
18811895
}
1882-
firebase.instance.child(path).setValue(null);
1883-
resolve();
1896+
1897+
const onCompletionListener = new com.google.firebase.database.DatabaseReference.CompletionListener({
1898+
onComplete: (error: any /* com.google.firebase.database.DatabaseError */, dbRef: any /* com.google.firebase.database.DatabaseReference */) => {
1899+
error ? reject(error.getMessage()) : resolve();
1900+
}
1901+
});
1902+
1903+
firebase.instance.child(path).setValue(null, onCompletionListener);
18841904
} catch (ex) {
18851905
console.log("Error in firebase.remove: " + ex);
18861906
reject(ex);

src/firebase.ios.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,9 +1777,8 @@ firebase.push = (path, val) => {
17771777
return new Promise((resolve, reject) => {
17781778
try {
17791779
const ref = FIRDatabase.database().reference().childByAppendingPath(path).childByAutoId();
1780-
ref.setValue(val);
1781-
resolve({
1782-
key: ref.key
1780+
ref.setValueWithCompletionBlock(val, (error: NSError, dbRef: FIRDatabaseReference) => {
1781+
error ? reject(error.localizedDescription) : resolve({ key: ref.key });
17831782
});
17841783
} catch (ex) {
17851784
console.log("Error in firebase.push: " + ex);
@@ -1791,8 +1790,9 @@ firebase.push = (path, val) => {
17911790
firebase.setValue = (path, val) => {
17921791
return new Promise((resolve, reject) => {
17931792
try {
1794-
FIRDatabase.database().reference().childByAppendingPath(path).setValue(val);
1795-
resolve();
1793+
FIRDatabase.database().reference().childByAppendingPath(path).setValueWithCompletionBlock(val, (error: NSError, dbRef: FIRDatabaseReference) => {
1794+
error ? reject(error.localizedDescription) : resolve();
1795+
});
17961796
} catch (ex) {
17971797
console.log("Error in firebase.setValue: " + ex);
17981798
reject(ex);
@@ -1804,16 +1804,18 @@ firebase.update = (path, val) => {
18041804
return new Promise((resolve, reject) => {
18051805
try {
18061806
if (typeof val === "object") {
1807-
FIRDatabase.database().reference().childByAppendingPath(path).updateChildValues(val);
1807+
FIRDatabase.database().reference().childByAppendingPath(path).updateChildValuesWithCompletionBlock(val, (error: NSError, dbRef: FIRDatabaseReference) => {
1808+
error ? reject(error.localizedDescription) : resolve();
1809+
});
18081810
} else {
18091811
const lastPartOfPath = path.lastIndexOf("/");
18101812
const pathPrefix = path.substring(0, lastPartOfPath);
18111813
const pathSuffix = path.substring(lastPartOfPath + 1);
18121814
const updateObject = '{"' + pathSuffix + '" : "' + val + '"}';
1813-
FIRDatabase.database().reference().childByAppendingPath(pathPrefix).updateChildValues(JSON.parse(updateObject));
1815+
FIRDatabase.database().reference().childByAppendingPath(pathPrefix).updateChildValuesWithCompletionBlock(JSON.parse(updateObject), (error: NSError, dbRef: FIRDatabaseReference) => {
1816+
error ? reject(error.localizedDescription) : resolve();
1817+
});
18141818
}
1815-
1816-
resolve();
18171819
} catch (ex) {
18181820
console.log("Error in firebase.update: " + ex);
18191821
reject(ex);
@@ -1923,8 +1925,9 @@ firebase.query = (updateCallback, path, options) => {
19231925
firebase.remove = path => {
19241926
return new Promise((resolve, reject) => {
19251927
try {
1926-
FIRDatabase.database().reference().childByAppendingPath(path).setValue(null);
1927-
resolve();
1928+
FIRDatabase.database().reference().childByAppendingPath(path).setValueWithCompletionBlock(null, (error: NSError, dbRef: FIRDatabaseReference) => {
1929+
error ? reject(error.localizedDescription) : resolve();
1930+
});
19281931
} catch (ex) {
19291932
console.log("Error in firebase.remove: " + ex);
19301933
reject(ex);

0 commit comments

Comments
 (0)