firebase database connection error handling - javascript

Does anyone know whether there is a way to properly check for errors in the initial connection with the Firebase database? This is my example code
const database = firebase
.initializeApp({ databaseURL: FIREBASE_URL })
.database();
and in order to test that my error handling was correct I tried deleting a character from the URL, but this just prints the following to the console:
FIREBASE WARNING: Firebase error. Please ensure that you spelled the name of your Firebase correctly (FIREBASE_URL)
I looked thoroughly through the documentation, the most relevant page I could find is this one, but even trying to use the enableLogging method and trying to regex whether it's a warning / error seems too flimsy because the above warning isn't even part of that logging.
If there was even just an attribute I could access to check whether the database is online that'd be great, or at best an error callback or something of the like.
Thank you for your time!

Related

ArangoDB: sends "statusCode: 0"

Have anyone encountered this Error message, when trying to connect to ArangoDB from a React application [See first attached photo]? It seemed like, it could be an issue related to authentication... but I've tried using "_system" and my own databases, with booth "root" as username and with "root" as password as well as setting the password to "null". I've tried to create new users and tried to connect to the database... Nothing works... (what am I doing wrong? - I've gone through the documentation a billion times at this point). I will attach a photo of my code as well.
Image of error,
Image of my code
Here is a link to the list of error codes. Unfortunately, "error 0" is extremely unhelpful. However, I see two potential issues.
First is with your use of HTTPS - normally, you use would use HTTP to connect to port 8529. One caveat would be TLS (like --server.endpoint "http+tcp://127.0.0.1:8529" with arangosh), but that's not the same as HTTPS.
Second, your AQL query seems to be attempting to return an entire collection, which is not how AQL works. Try returning a static like RETURN 'yes' or use the format:
FOR doc IN collection
RETURN doc

enableWhiteboard() function getting a response with SERVICE_EXCEPTION error in Circuit SDK

I am trying to enable Whiteboard using Circuit SDK by running enableWhiteboard(callId, viewbox), where callId is the ID of the current call and viewbox an object containing the device's screen width and height. When I call it, the response code is "SERVICE_EXCEPTION" and errorCode is "UNEXPECTED_ERROR", with info being "General Client API service exception: null".
The log captured using Chrome is linked below:
Circuit SDK - enableWhiteboard() log
What am I doing wrong? That exception is turning out to be hard to debug, but I think I may be missing something.
Thanks!
Yes, we are working on improving these errors.
Whiteboarding still requires special permissions that only the system admin can set. Please let me know the user(s) or bots you'd like to have the permission assigned.

Firebase: How to handle invalid firebaseConfig passed to firebase.initializeApp()

I am having an angular app which connects to 2 firebase projects:
The default project is connected on app load via AngularFireModule.initializeApp(environment.firebaseConfig) (AngularFire2)
The secondary project is connected at run time via firebase.initializeApp(firebaseConfig, 'pr1'); (Firebase JS SDK)
Now the firebase config of the 2nd project is received from user through UI. So I need to validate if the firebase project exists with given credentials, before I could do any operation.
Calling res = firebase.initializeApp(firebaseConfig, 'pr1'); with invalid apiKey, authDomain, projectId, storageBucket, etc., is not throwing any error, but successfully returning a FirebaseAppImpl object.
After initialization, calling
res.auth()
res.storage()
also doesnt throw any errors but returning me proper objects.
Only for res.database(), I am getting a console warning as follows:
#firebase/database: FIREBASE WARNING: Firebase error. Please ensure that you spelled the name of your Firebase correctly (https://[invalid-url].firebaseio.com)
But its not throwing any errors, that I could act on.
I need to validate the given keys, and alert the user that 1 or more key is wrong. Any suggestions on how to do this?
Update 1:
Had a look at Firebase Management API: https://firebase.google.com/docs/projects/api/reference/rest
It has many functions like creating, retrieving projects.
But I am not sure, how to make use of any of these APIs to my requirement.

Firestore: code 16 (Request had invalid authentication credentials)

i am trying to access Firestore with admin permissions via private key and admin permissions so i can use it for queries and stuff in the backend.
//i import fb-admin
const firebaseAdmin = require('firebase-admin')
//i initialize as admin with a valid credential
firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert('./pathto/myprivatekeyinfo.json')
})
//i initialize firestore
var dba = firebaseAdmin.firestore()
//i test the connection by listing all the available collections
dba.getCollections().then(collectionList => {
collectionList.forEach(collection => {
console.log(collection.id) //print available collections
}
},error => console.error(JSON.stringify(error,null," "))) //print error
It seems exactly like instructed in the documentation, but my problem is that with some computers that i try to execute Node in, i only manage to connect at random on a few.
Sometimes i connect and it goes fine, printing the available collections as it should, but most of the time all i get is this error for invalid credentials
{
"code": 16,
"metadata": {
"_internal_repr": {
"www-authenticate": [
"Bearer realm=\"https://accounts.google.com/\""
]
}
},
"details": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"note": "Exception occurred in retry method that was not classified as transient"
}
i've tried changing nothing and it works sometimes on some computers where i test the exact same code, but in others it doesn't, and trying to get a new private key via the firebase console changes nothing in the matter. When i try to connect it sometimes takes too long just to get this error or it does not call back at all. The link provided isn't helpful either, as it only gives some JS code for regular access via the front end to login with google which isn't my use case at all in this situation (i've tried the "configure a project" button too).
is there anything that i am doing really wrong here? why does it work sometimes although changing nothing and sometimes it just doesn't?
i appreciate any help
This error is basically the same to this one (Not able to send device push notification due to app/invalid-credential error), where the clock of the computer needs to be synced to the clock of the firebase server.
i was stuck trying to test it in various computers (all with the wrong set up clock) without being able to connect before a friend tried to point out that, so i tested and it worked.
The solution that worked for me was definitely to check the set up clock on the computer.

Firebase Realtime Database stopped working

For the past month or so I have been developing an app with Firebase's Real-time Database. It has been working great until today. For some reason, the database querying stopped working entirely. The authentication (email and password login, create an account, forgot password) all seem to work fine but for some reason, my app cannot retrieve the Firebase data.
Keep in mind that it was working for a whole month and I have changed nothing.
I even went to previous builds of my app to test them out. They worked when tested and they also cannot connect to the database.
Has anybody ever faced this problem before and if so how did you manage to fix it?
This is my code by the way but it was working moments ago so I doubt anything is wrong with it.
var firebaseResponse = firebase.database().ref().orderByChild("country").equalTo(country)
fireBaseResponse.once('value').then(snapshot => {
snapshot.forEach(item => {
const temp = item.val();
data1.push(temp);
});
There was a Firebase service disruption started today at 12:20 (US/Pacific).
For more info you can track Firebase Status here
Weird timestamp rule in Firebase console
I faced a similar problem in one of my projects. It was loading data since yesterday but today it does not return anything.
I don't know how but this weird timestamp rule got added by default when I created the rule in my Firebase project.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020,8, 22);
}
}
}
So I just removed the request.time < timestamp.date(2020,8, 22) rule and replaced it with this.
allow read, write: if true;
Note:
allow read, write: if true; make your database public for read/write request. Add some security rules.
Funny note:
I was pretty sure that the problem was with my service.json file. So I checked everything but the rules because firebase does not add timestamp rule by default. Maybe I copied the rule from somewhere.
How did I figure out this?
By luck and by logcat.
When I deep dived into logcat I found this warning message
[Firestore]: Listen for Query(deck_collection order by name) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}

Categories