Skip to content

[platform-server] vague error when entire URL is not provided for Http #15349

Closed

Description

@MarkPieszak

I'm submitting a ... (check one with "x")

[x] bug report
[x] (or) feature request

Current behavior
When calling a rest local rest API for example /api/getproducts, the server Http throws a vague error

ERROR { Error: Uncaught (in promise): Error at resolvePromise

Providing the entire URL fixes it: (but user would never know to do this)

this.http.get('http://localhost:5000/API/test') 

Expected behavior

Previously (angular2-universal) we set the origin-URL for the user in these situations, so if we don't want to add that same behavior,
we need to make sure to Throw a more specific error letting the Dev know why the server didn't render that Http response. (Note the rest of the app actually renders it doesn't break rendering).

Also Docs should reflect whatever we decide to do here as well, to prevent confusion.

Minimal reproduction of the problem with instructions

this.http.get('/API/test') 

What is the motivation / use case for changing the behavior?
Previous Users of Universal might be confused why his existing functionality doesn't work anymore, especially if not given a good Error message explaining it.

  • Angular version: 4.0.0.rc5 (or nightly build)

CC/ @vikerman @alxhub @gdi2290

Activity

  1. hheexx commented on Mar 28, 2017

    @hheexx

    @MarkPieszak @alxhub
    What is recommended way to do http now ?

    why was angular2-universal solution of providing origin abandoned? Security?

    I will probably inject host string with different values for browser/node and prepend it to all urls for now.

  2. MarkPieszak commented on Mar 28, 2017

    @MarkPieszak
    Author

    Well in Angular2-universal we assumed it was localhost if you didn't provide a full URL. The server doesn't handle relative URLs so the whole must be provided there.

    In the providers you pass into the ngAspnetCoreEngine here, just pass in another Provider there, that has the Origin URL. Have all your Http calls prepend it automatically.

    Most cases people are using external Rest endpoints anyway, it's not often they're served from the same location.

  3. hheexx commented on Mar 28, 2017

    @hheexx

    That is exactly what I have done. Thanks.

        const providers = [{
            provide: INITIAL_CONFIG,
            useValue: {
                document: '<app></app>', // Our Root application document
                url: params.url
            }
        },
        {
            provide: 'ajaxHost',
            useValue: params.origin
        }
        ];
    
  4. PickRelated commented on Jun 22, 2017

    @PickRelated

    What about people using ngx-translate? It uses relative URL to get translation file.

    P.S. the above solution does not work for me. Link is broken, so I have used hheexx's answer.

  5. added a commit that references this issue on Aug 11, 2017
    6e5623c
  6. added a commit that references this issue on Aug 28, 2017
    28bd59b
  7. angular-automatic-lock-bot commented on Sep 11, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Sep 11, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions