"Possible Unhandled Promise Rejection (id: 2)" expo-file-system - javascript

I am trying to download a video using expo-file-system. It used to work sometimes, but sometimes gave me this error. Now I changed some stuff (I don't remember exactly what) and now I'm getting the error constantly.
const result = await FileSystem.createDownloadResumable(
`http://192.168.0.12:5000${data.staticPath}`,
vidDir + data.path,
{},
(downloadProgress) => {
console.log(downloadProgress);
}
).downloadAsync().catch(function(error) {
console.log("Error: " + error.message);
throw error;
});
The downloadProgress shows that the download is nearly done but then the error happens and the download stops
LOG {"totalBytesExpectedToWrite": 5632573, "totalBytesWritten": 5089880}
LOG Error: unexpected end of stream
WARN Possible Unhandled Promise Rejection (id: 2):
Error: unexpected end of stream
construct#[native code]
construct#[native code]
_construct#http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:19240:28
Wrapper#http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:19202:25
construct#[native code]
_createSuperInternal#http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:94967:322
CodedError#http://192.168.0.12:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:94975:26
This is the server code, made with Flask, and it just returns the static path of the file to be downloaded
#app.route("/requestVideo/<url>")
def requestVideo(url):
path = vid_request.download(url, "static")
info = {
"path": path,
"staticPath": url_for('static', filename=path)
}
return jsonify(info)
How can I fix it so the download finishes?

Related

create-react-app: "The development server has disconnected. "

There are several questions about this error, but none of them fit exactly my circunstances. Let me explain: I'm writing some code using create-react-app that makes an AJAX call to an external server:
async ajaxCall(url) {
var objetorespuesta = null;
try {
let respuesta = await fetch(url);
if (respuesta.ok) {
objetorespuesta = {
"status": { status: "ok" },
"datos": await respuesta.json()
};
}
else {
objetorespuesta = {
"status": {
status: "error",
errorcode: respuesta.status,
errortext: respuesta.statusText
}
};
}
}
catch (e) {
console.log("Call failed!!");
objetorespuesta = {
"status": {
status: "error",
errorcode: "Error de red",
errortext: e
}
};
}
return objetorespuesta;
}
let url = "https://blablabla" //My URL here; edited out;
const objetorespuesta = this.ajaxCall(url);
for (let key in objetorespuesta) {
console.log("Mooooo: " + key + ": " + objetorespuesta[key]);
}
Now, before I added the "try/catch" block, I got in the console an:
Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.
The development server has disconnected. Refresh the page if necessary
Which I believe it's because of CORS, since I'm not calling localhost but an external URL. I'll deal with that later, but for the moment I decided to add the "try/catch" so that the code catches that error and can keep executing...
...except that it doesn't do that. When the error happens, nothing gets executed anymore. What I mean is that if the code worked, the network call would fail, but I'd get several "Mooooo" messages in the console with the variables of the returned object. Instead, what I get is:
Call failed!!
The development server has disconnected. Refresh the page if necessary.
It seems that the development server get disconnected right after the network call fails.
What's going on? The development server fails, but the JS code is being executed in my browser, so it should have no influence, right? Or is there some other error in my code that I'm missing?

Firebase Cloud Functions returns INTERNAL Error

In the below code, while I'm trying to insert data into firebase Firestore, the data gets inserted but on returning promise, it returns error as INTERNAL Error. Hera is the console logged Error
Error: INTERNAL
at new f (error.ts:66)
at y (error.ts:175)
at O.<anonymous> (service.ts:231)
at tslib.es6.js:100
at Object.next (tslib.es6.js:81)
at r (tslib.es6.js:71) "INTERNAL"
The Code in Cloud Functions (index.js)
exports.addNewBook = functions.https.onCall((data, context) => {
return admin.firestore().collection('books').add(data.book)
.then((doc) => { return doc })
.catch((error) => { return error });
});
The Client Function invoking the Cloud Function (Client Function)
const addNewBooks = (formData) => {
bookData = {
no: formData.bookNo.value,
name: formData.bookName.value,
author: formData.bookAuthor.value,
publisher: formData.bookPublisher.value,
librarian: formData.librarianName.value
}
console.log(bookData);
const addBooksToDb = firebase.functions().httpsCallable('addNewBook');
addBooksToDb({
book: bookData
})
.then(doc => {
console.log(doc, doc.id)
})
.catch(error => {
console.log(error, error.message)
});
}
$("#addBookModalForm").submit(function(e) {
e.preventDefault();
addNewBooks(this);
this.reset();
});
Error logged on Cloud Functions on console.log() in index.js
addNewBook
Unhandled error RangeError: Maximum call stack size exceeded
at isArrayLike (/srv/node_modules/lodash/lodash.js:11333:31)
at keys (/srv/node_modules/lodash/lodash.js:13307:14)
at /srv/node_modules/lodash/lodash.js:4900:21
at baseForOwn (/srv/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/srv/node_modules/lodash/lodash.js:13400:7)
at encode (/srv/node_modules/firebase-functions/lib/providers/https.js:179:18)
at /srv/node_modules/lodash/lodash.js:13401:38
at /srv/node_modules/lodash/lodash.js:4905:15
at baseForOwn (/srv/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/srv/node_modules/lodash/lodash.js:13400:7)
What is the reason for throwing an INTERNAL Error
The promise returned from add() probably rejected and generated an error. If you don't take care to send a specific, known response to the client, you could see an error on the client.
Since we can't see the exact inputs and outputs (you are just showing variables here), and the log output, we have no way of knowing exactly what happened, so you will have to debug this to figure out what went wrong.

Pino error log is empty, although error object contains information

I have written a small error handling function, which is invoked after an AXIOS request, like so:
try {
...
} catch (error) {
handleAxiosError(error);
}
The function is as follows:
function handleAxiosError(error) {
if (error.response !== undefined) {
logger.error(`Received a HTTP error. Status code: ${error.response.status}, Data: ${error.response.data}`);
} else if (error.request !== undefined) {
logger.error(error.request);
} else {
logger.error(error.message);
}
throw new Error(error);
}
Although an error is thrown:
(node:94324) UnhandledPromiseRejectionWarning: Error: Error: connect ECONNREFUSED 127.0.0.1:6557
at handleAxiosError (C:\pathtoapp\utils\utils.js:66:11)
Pino only saves the following to the log. I can't find the problem. Is this an async issue?
{"level":50,"time":1567435455281,"pid":94324,"hostname":"host","name":"app","res":{},"v":1}
Thanks!
When using async logging (the default for the Pino logger), the process might have exited before all of the logging has been processed.
See https://github.com/pinojs/pino/blob/HEAD/docs/asynchronous.md
You can also change the logging to be synchronous, and you won't have this problem:
const dest = pino.destination({ sync: true })

Cant get attributes from error object

I am connecting to the Facebook API and I receive this error
{ [Error: failed [500] {"error":{"message":"Invalid parameter","type":"FacebookApiException","code":100,"error_subcode":1349125,"is_transient":false,"error_user_title":"Missing Message Or Attachment","error_user_msg":"Missing message or attachment."}}] stack: [Getter] }
I want to receive the error_user_msg
try {
var response = Social.createPosting(graphType, data);
} catch (exception) {
console.log(exception)
throw new Meteor.Error(exception.error_user_msg)
}
Problem is only message attribute is defined on the Error object that is returned.
exception.message returns
failed [500] {"error":{"message":"Invalid parameter","type":"FacebookApiException","code":100,"error_subcode":1349125,"is_transient":false,"error_user_title":"Missing Message Or Attachment","error_user_msg":"Missing message or attachment."}}
Which is a String, but is not valid JSON, so I cannot parse it either
What am I missing?

Meteor HTTP.get error handling

I am trying to perform HTTP.get on a set of URLs asynchronously using futures.
Meteor version: 0.8.3
Platform: Windows server 2012
The code is somewhat like this:
var futures = _.map(test, function(url) {
var future = new Future();
var onComplete = future.resolver();
try{
// Make async http call
var httpGet = HTTP.get(url,{followRedirects: true},function(error, result) {
if(error)
{
apiLogger.error("%s is error",error);
onComplete(error, null);
}
else
{
if(result!=null){
//operations done here
onComplete(error, JSON.stringify(object1));
}
else {
apiLogger.error('%s - User encountered an error. URL not parsed: %s',user,url);
onComplete(error, null);
}
}
});
}
catch(e)
{
apiLogger.error('%s - URsarsed: %s - %s',user,url,result.statusCode);
onComplete(error, null);
}
return future;
});
The issue I am facing is improper error handling.
I am getting the following error on some URLs:
I20140904-17:57:38.609(-4)? Exception while invoking method 'parallelAsyncJob' E
rror: failed [404] <html><head><title>Apache Tomcat/7.0.12 - Error report</title
><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color
:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;ba
ckground-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;
color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,A
rial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial
,sans-serif;color:white;background-colo...
I20140904-17:57:38.617(-4)? at packages/underscore/underscore.js:255
I20140904-17:57:38.619(-4)? at Array.map (native)
I20140904-17:57:38.621(-4)? at Function._.map._.collect (packages/underscore
/underscore.js:123)
I20140904-17:57:38.623(-4)? at Function._.invoke (packages/underscore/unders
core.js:254)
I20140904-17:57:38.626(-4)? at Meteor.methods.parallelAsyncJob (app/server/m
ethods.js:1:9355)
I20140904-17:57:38.628(-4)? at maybeAuditArgumentChecks (packages/livedata/l
ivedata_server.js:1488)
I20140904-17:57:38.631(-4)? at packages/livedata/livedata_server.js:650
I20140904-17:57:38.632(-4)? at _.extend.withValue (packages/meteor/dynamics_
nodejs.js:37)
I20140904-17:57:38.635(-4)? at packages/livedata/livedata_server.js:649
I20140904-17:57:38.644(-4)? at _.extend.withValue (packages/meteor/dynamics_
nodejs.js:37)
I20140904-17:57:38.646(-4)? - - - - -
I20140904-17:57:38.648(-4)? at makeErrorByStatus (packages/http/httpcall_com
mon.js:12)
I20140904-17:57:38.650(-4)? at Request._callback (packages/http/httpcall_ser
ver.js:99)
I20140904-17:57:38.652(-4)? at Request.self.callback (C:\Users\Administrator
\AppData\Local\.meteor\tools\edf8981bb6\lib\node_modules\request\request.js:122:
22)
I20140904-17:57:38.655(-4)? at Request.EventEmitter.emit (events.js:98:17)
I20140904-17:57:38.657(-4)? at Request.<anonymous> (C:\Users\Administrator\A
ppData\Local\.meteor\tools\edf8981bb6\lib\node_modules\request\request.js:888:14
)
I20140904-17:57:38.660(-4)? at Request.EventEmitter.emit (events.js:117:20)
I20140904-17:57:38.662(-4)? at IncomingMessage.<anonymous> (C:\Users\Adminis
trator\AppData\Local\.meteor\tools\edf8981bb6\lib\node_modules\request\request.j
s:839:12)
I20140904-17:57:38.665(-4)? at IncomingMessage.EventEmitter.emit (events.js:
117:20)
I20140904-17:57:38.668(-4)? at _stream_readable.js:920:16
I20140904-17:57:38.669(-4)? at process._tickCallback (node.js:415:13)
Am I doing something wrong? Or is it some GET issue?
Update:
I am using futures because the final operation can only be performed after getting all the URLs.
Interesting thing, I am able to open the URL via browser, and even POSTMAN and getting 200 status. But meteor get is receiving 404.
Per your error message, you’re getting a 404 error code; some of your URLs are invalid. And you say yourself that it only happens on certain URLs.
Why is your code so complicated, with all these futures? HTTP.get() itself offers an asyncCallback, and you’re already using inline callbacks in your code, so why not just strip out all the futures stuff?
_.map(test, function(url) {
try {
// Make async http call
HTTP.get(url, {followRedirects: true}, function(error, result) {
if (error) {
if (result.statusCode == 404)
apiLogger.error('Error 404, URL not found: %s', url);
else
apiLogger.error('Error %s from %s for user %s',
result.statusCode, url, user);
return false;
} else {
if (result != null) {
// operations done here
} else {
apiLogger.error('Empty or invalid result returned from %s for user %s',
url, user);
}
return false;
}
});
} catch (error) {
return false;
}
});

Categories

Resources