-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle response message #16
Comments
First, thank you for this plugin. Second, I would also love to have the ability for a response message from the server to be passed back so that, if something goes wrong on the server, a reason for the error can be displayed to the end user. In the meantime, can you tell me how the module's error event is currently being triggered? I thought that I could set the HTTP status code of the server script to be 404 or 422 and that would trigger bg-http's error event, but it does not seem to be working that way. Any help appreciated. Thanks! |
Is there any implementation for this as yet? I am uploading a file to parse server where the server returns a json object containing the url for the file which is needed by my app. |
How can I get the response from the server? That will be great |
I have a similar situation as dondragon2. I cant currently utilize any data that my api sends back after a successful upload, like a photo id created in my photos table for example. Are there plans to implement this enhancement? |
`URLSessionDataTaskDidReceiveData(session, dataTask, data) {
}` |
THANK YOU @developper89 🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮🌮 |
FYI for all who find this thread, until @PanayotCankov releases an official enhancement, here's how you can get access to the data via the task in your models. This is only for iOS, mind you: In background-http.ios.js:
You can call the eventName whatever you want. I perform all my done uploading operations when that event is fired, for example:
|
@davecoffin I found an issue with this code, basically since Tasks are stored as a WeakMap (line 187 of that file) I am losing the "task" sometimes but very often, so when I get my response back the task is not there anymore and what I get back is new Task instead, I had to get rid of the WeakMap, I am thinking about making a PullRequest and see if it gets approved by also using your approach along with my "fix" |
and fixes an issue with Tasks disapearing when using a WeakMap (NativeScript#16)
How does this work for android? Is there are solution or a workaround? |
I've added the server response to the complete event arguments and created a pull request |
how to read server response data? |
The event provided to the "complete" callback contains the response:
|
@AceTheFace Does that solution still work? |
@Ericky14 |
@developper89
|
@Ericky14 It looks like you are tying into the complete event, the event that returns data is "responded". |
@davecoffin
But I believe it is most likely a problem with the back-end. The back-end works for uploading from web, but not from mobile with nativescript. |
@Ericky14 Your problem appears to be that you are logging a json object. You are probably getting the data just fine, but you cant console.log an object. Try this:
|
@Ericky14 To your point about uploading from web vs nativescript, if you can interact with your API using Postman, you should be able to from your app. What authentication does your server use? To get set up I'd write a method in your backend to return a string with no authentication, just as a proof of concept. Once your app is communicating with your backend you know that your problem exists in your execution. |
I get errors unless I modify the code to be what @developper89 posted: BackgroundUploadDelegate.prototype.URLSessionDataTaskDidReceiveData = function (session, dataTask, data) {
dispatch_async(main_queue, function () {
var jsTask = Task.getTask(session, dataTask);
var jsonString = new NSString({ data: data, encoding: NSUTF8StringEncoding });
jsTask.notify({ eventName: "responded", object: jsTask, data: JSON.parse(jsonString.toString()) });
});
}; |
How to ready in case of error , it does not goes to responded. i want to read response |
same, I would like to get a response when I have an error? however at the moment it only shows the code which isn't that useful in accurately diagnosing what's wrong with the request I've sent. |
Same here, please reopen this issue. |
@mshanak @davecoffin @developper89 @peterbsmyth @friedolinfoerder I still have same issue for android in case of api failure, I wanted to take the error json response from server but reponded & complete events are not triggered, can anyone please get back me with the solution, thanks in advance |
@mshanak @davecoffin @developper89 @peterbsmyth @friedolinfoerder I have same issue, unable to handle the response coming from server with 400 status for andriod. Here is my code
} |
The text was updated successfully, but these errors were encountered: