Skip to content

Error message given by fetch for xhr.onerror is not useful #2952

Closed

Description

@adamvoss

Did you verify this is a real problem by searching Stack Overflow and the other open issues in this repo?

Yes. I did not see a direct match yet on StackOverflow for NativeScript though I did find this same issue for React Native on StackOverflow. A related issue against the fetch.js NativeScript derived its implementation from is JakeChampion/fetch#367.

Tell us about the problem

The function assigned to xhr.onerror does not propagate helpful information concerning the error that occurred, instead only "Network request failed" is presented.

Which platform(s) does your issue occur on?

Both (tested on Android)

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.3.0
  • Cross-platform modules: 2.3.0
  • Runtime(s): tns-android (2.3.0)
  • Plugin(s): none

Please tell us how to recreate the issue in as much detail as possible.

Create a new project using the typescript template. Use the code below and observe the output on the console.

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

app.ts

import * as app from 'application';

fetch("unknownProtocol://whatever", {
  method: "POST",
  body: JSON.stringify({}),
  headers: {
    "Content-Type": "application/json"
  }
})
  .then(resp => resp, error => {
    console.log(error);
    return error;
  });

app.start({ moduleName: 'main-page' });

Proposed fix

I would like to submit a PR that changes fetch.js from

xhr.onerror = function () {
    reject(new TypeError('Network request failed:'))
}

to

xhr.onerror = function (error) {
    reject(new TypeError('Network request failed: ' + error.message))
}

In changing teh above you get an more helpful error such as,

TypeError: Network request failed: java.net.MalformedURLException: unknown protocol: unknownprotocol

instead of,

TypeError: Network request failed

Activity

  1. changed the title [-]Improve xhr.onerror error message given by `fetch`[/-] [+]Error message given by `fetch` for xhr.onerror is not useful[/+] on Oct 24, 2016
  2. NickIliev commented on Oct 25, 2016

    @NickIliev
    Contributor

    Hey, @vossad01 we are open source product and we are welcoming all contributors.
    In order to create PR you should first sign the CLA (Contribution License Agreement) and once added to our contributors list you can post your PR. The process is few steps only and once ready create your PRs against the master branch - they will be revised from other member and when tested and upvoted they can be merged.

    More about contributing can be found here.

  3. NickIliev commented on Oct 26, 2016

    @NickIliev
    Contributor

    Hey @vossad01 have you managed to create the PR - let me know if you need any assistance in the process

  4. adamvoss commented on Oct 27, 2016

    @adamvoss
    ContributorAuthor

    Hi @NickIliev. I signed the CLA but have been having trouble getting the tests to run. If you can provide any assistance that would be great.

    I figured out that I need to put adb and emulator from Android Studio on my path.

    I've done:

    npm install
    grunt
    grunt testsapp --platform=Android --emuPId=".*emulator64-x86" --avd="Nexus_5_API_24" --showEmu=true

    I have to remove the -no-audio from the startAndroidEmulator task or exec:startAndroidEmulator fails saying

    qemu-system-i386: -audio: invalid option

    After removing that flag, the emulator launches but exec:npm-i-modules fails saying

    addLocal Could not install /home/vossad01/dev/NativeScript/bin/dist/tns-core-modules-undefined.tgz

    I have a /home/vossad01/dev/NativeScript/bin/dist/tns-core-modules-*2.5.0*.tgz but not `tns-core-modules-undefined.tgz

    If manually rename the files, then exec:npm-i-modules completes. However, the app in the emulator errors:

    Unhandled Exception
    java.lang.RuntimeException: Unable to start activity ComponentIngo{org.nativescript.TestsApp/com.tns.NativeScriptActivity}:
    com.tns.NativeScriptException:
    Callingjs method onCreate failed

    Error calling module function

    Error calling module function

    Error calling module function

    Error calling module function

    TypeError: Cannot read property 'FLEX_DIRECTION_ROW' of undefined
    ...

    I'm not really sure where to go from there.

  5. NickIliev commented on Oct 27, 2016

    @NickIliev
    Contributor

    Hey @vossad01

    Use this developers workflow which is updated and a lot of the works is now automated by npm scripts. Meanwhile, we will check the contributing guide for the errors you have described as it appears that some of the actions are now obsolete.

    For a one-line fix you can directly create your PR against the master - once it gets upvoted by other members it will be automatically tested with the CI and when tests are OK it can be merged into master.

  6. adamvoss commented on Oct 28, 2016

    @adamvoss
    ContributorAuthor

    @NickIliev that helped a lot! Thanks! I had been trying to use the instructions for running the tests.

    I have the tests running now. I should be able to implement this tomorrow.

  7. lock commented on Aug 29, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  8. locked and limited conversation to collaborators on Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions