Coder Social home page Coder Social logo

Error: We're sorry, a server error occurred. Please wait a bit and try again. (line 303, file "Code", project "FirebaseApp") about firebaseapp HOT 14 OPEN

romainvialard avatar romainvialard commented on May 30, 2024 1
Error: We're sorry, a server error occurred. Please wait a bit and try again. (line 303, file "Code", project "FirebaseApp")

from firebaseapp.

Comments (14)

vn78dev avatar vn78dev commented on May 30, 2024 2

Solved it. The library error was triggered by the pair
"urlFetchWhitelist": ["https://www.example.com/"]
in my manifest json. Once I removed it, requests became successful.
I am not sure whether it's a library problem though.

from firebaseapp.

RomainVialard avatar RomainVialard commented on May 30, 2024 2

@vn78dev getData() supports optQueryParameters as a second parameter.
https://github.com/RomainVialard/FirebaseApp#getdatapath-optqueryparameters

For pagination you can use parameters like limitToFirst & startAt
https://firebase.google.com/docs/database/rest/retrieve-data#section-rest-filtering

from firebaseapp.

vn78dev avatar vn78dev commented on May 30, 2024 1

I am getting this error again - now it looks like it's triggered by Firebase limits for the number/length of keys. My database has grown and I am trying to implement a sort of pagination - with little success though as getData returns all the keys for a given path. Have you considered introducing pagination or 'ranged' requests, @RomainVialard? Or maybe there is an easier solution for this?

from firebaseapp.

derrickrc avatar derrickrc commented on May 30, 2024

OK, it seems to be working on my personal gmail and not my gSuite, I must have hit some limit yesterday. What are the limits? When will this reset? Midnight has come and gone my time and it's still throwing the error. Thank you.

from firebaseapp.

vn78dev avatar vn78dev commented on May 30, 2024

I started getting the same error today. Nothing really changed in the code or scopes, but Stackdriver log refers to the FirebaseApp library.

error1

log

from firebaseapp.

derrickrc avatar derrickrc commented on May 30, 2024

I started getting the same error today. Nothing really changed in the code or scopes, but Stackdriver log refers to the FirebaseApp library.

error1 log

Is it possible you hit the Apps Scripts usage limit for urlfetch calls?

from firebaseapp.

vn78dev avatar vn78dev commented on May 30, 2024

no way, I ran fetches sort of 2 or 3 times today..

from firebaseapp.

vn78dev avatar vn78dev commented on May 30, 2024

see if this screenshot helps, looks like "line 234" refers to the FirebaseApp code, not mine:

image

from firebaseapp.

derrickrc avatar derrickrc commented on May 30, 2024

It looks like that's the line for throwing a generic error, hence why we don't get more detail on the error. I just ran my code and it executed. I'd try running it on a different gmail account to confirm you didn't exhaust your quota. Good luck.

from firebaseapp.

vn78dev avatar vn78dev commented on May 30, 2024

I checked all the quotas and limits, including script runtime limit etc - nothing suspicious there. I then created a small test function just knocking to a database and received the same error. I ran it under another user and that didn't help too :(

Test function:

function testFb () {
  var dbUrl = "https://test.firebaseio.com/";
  var dbToken = ScriptApp.getOAuthToken();
  var db = FirebaseApp.getDatabaseByUrl(dbUrl, dbToken);
  Logger.log(JSON.stringify(db));
  var data = db.getData("testKey");
  Logger.log(data);
}

For some reason, the function returned url and the token:
{"base":{"url":"https://test.firebaseio.com/","secret":"ya29.ImyUB9.........d778bbE"}}

If this helps with any ideas what might be wrong, I'd appreciate your help very much.

from firebaseapp.

affordablequalityhomes avatar affordablequalityhomes commented on May 30, 2024

I'm getting the same error, in FirebaseApp_._sendAllRequests

So as per the comment above, I tried:

function test() {
  var m = UrlFetchApp.fetch('http://www.microsoft.com');
}

and that gave me a different error:

Exception: Service invoked too many times for one day: urlfetch.
at ...

The quota for urlfetch is 20,000 / day

from firebaseapp.

marcomow avatar marcomow commented on May 30, 2024

I was able to solve this making a copy of the original library and adding there into the manifest appsscript.json this line "oauthScopes": ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/firebase.database", "https://www.googleapis.com/auth/script.external_request"] .

I suggest @RomainVialard to add these scopes into the original library, this will have also the nice side-effect of non constraining the users of the library to manual update of the scopes.

from firebaseapp.

dginovker avatar dginovker commented on May 30, 2024

I created a general purpose function based on Romain's answer above. This will solve your "server error occurred" if the problem is you're pulling too much data:

// Reads data from Firebase Database that is >50Mb
// Splits up the read calls based on data keys
function readBulkDataFromFirebase(url, split = 1, start = " ") {
  // log(`Debug: Searching for next ${split} from [${start}]`);
  let base = FirebaseApp.getDatabaseByUrl(url, env.token);
  let data = base.getData("", { orderBy: "$key", startAt: start, limitToFirst: split });

  if (!data) return null;

  // If we got more data, recursively call and add the data further down
  let nextStart = Object.keys(data).sort((a, b) => b - a)[0] + " "; // The last key we grabbed plus space " "
  return {...data, ...readBulkDataFromFirebase(url, split, nextStart)};
}

Basically it works by grabbing the first split children of an object, then the next split, etc etc. Data is sorted based on keys to get an order, and a space character is added to the last pulled key so the next key we pull is the one that comes after it. When calling the function, choose a value of split that guarantees the getData() call won't pull down more than 50Mb at a time (easy to test this, just pick a value like 100, if you still get the error reduce it).

If any single child is over 50Mb, this solution won't work and you'll have to do something else

from firebaseapp.

rahullraghuwanshi avatar rahullraghuwanshi commented on May 30, 2024

@dginovker the solution given by you runs endlessly and faces an execution time-out issue. Is there any solution?

from firebaseapp.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.