Reputation: 475
In reference to the Firebase set() function, is there a way to detect if the set() failed due to security rule errors?
Sample code (receives null
, indicating success, even if the set actually failed due to security rules):
locationRef.set('someValue', function(error) {
console.log(error);
});
The Firebase docs say that the callback only receives an error if synchronization has failed, but it would be useful get passed an error for security rules too. This way I can confidently tell a user that their data has been saved.
Is there any way to do this? I suppose it would useful for any read/write function with an onComplete callback.
Upvotes: 2
Views: 500
Reputation: 40582
In the case of a security error, the error object will contain a PERMISSION_DENIED code: http://jsfiddle.net/katowulf/ZG9CY/
For instance, if I run the following against a protected path:
new Firebase(URL).set({ hello: 'world' }, function(error) {
$('pre').text( 'done: '+ JSON.stringify(error) );
});
I get the following:
done: {"code":"PERMISSION_DENIED"}
There is a doc somewhere talking about the error codes, when I find it I'll add it to this post. (nope, it's about authentication errors)
Upvotes: 4