Skip to content
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

Content Type parsing error #46

Closed
skol-pro opened this issue Mar 17, 2016 · 18 comments
Closed

Content Type parsing error #46

skol-pro opened this issue Mar 17, 2016 · 18 comments
Assignees
Labels
Milestone

Comments

@skol-pro
Copy link
Contributor

I simply tried using the sample code on the readme (replacing urls of course), but I just get the following error:
apiRoot.$request is not a function

Any help would be appreciated. :-/

@maennchen
Copy link
Contributor

Could you console.log the apiRoot?

@skol-pro
Copy link
Contributor Author

Wow, fast answer, was expecting to wait for hours :-)
Sure, looks like I get the common stuff from $http:

Controller code:

$rootScope.apiRoot = $http({url: 'http://localhost:8080/api-1.0/'});

$rootScope.$watch('apiRoot', function(apiRoot){
    if (apiRoot != undefined) {
        $rootScope.dashboards = apiRoot.$request().$get('foo');
    }
});
Object {}
    catch: function (a)
    error: function (a)
    finally: function (a)
    success: function (a)
    then: function (b,f,h)
    __proto__: Object

@maennchen
Copy link
Contributor

Which version are you on? v2.0.0-alpha.4?

@skol-pro
Copy link
Contributor Author

I edited my last post with the ctrl code.
And I simply took the angular-hal.min.js from the git repo.

@maennchen
Copy link
Contributor

Ah, I see the error in my README.

Try this:

$http({url: 'http://localhost:8080/api-1.0/'})
  .then(function(apiRoot) {
    $rootScope.apiRoot = apiRoot;
  });

$rootScope.$watch('apiRoot', function(apiRoot){
    if (apiRoot != undefined) {
        $rootScope.dashboards = apiRoot.$request().$get('foo');
    }
});

@skol-pro
Copy link
Contributor Author

Yeah, I spotted that too, and tried to assign in then, without really real success :(

Still getting:
angular.min.js:93 TypeError: apiRoot.$request is not a function

@maennchen
Copy link
Contributor

What Content-Type does your server send with the answer?

@skol-pro
Copy link
Contributor Author

Content-Type: application/hal+json;charset=UTF-8
Is there something wrong with it ?

@skol-pro
Copy link
Contributor Author

Looks like $http has been kept untouched. I mean, I guess angular-hal is extending default $http, right ? :-)

@maennchen
Copy link
Contributor

@skol-pro
Copy link
Contributor Author

Well spotted !
Something like this would be better then ?!...

if (response.headers('Content-Type').indexOf(CONTENT_TYPE) > -1) { ... }

EDIT: Doing so make it works on my side at least :p

@maennchen
Copy link
Contributor

I think it would be good to integrate a library like this one:
https://www.npmjs.com/package/content-type

@skol-pro
Copy link
Contributor Author

Not a bad idea indeed, since it's a pretty lightweight library.

@maennchen
Copy link
Contributor

Would you be interested to make a pull request for that?

@skol-pro
Copy link
Contributor Author

You mean, to add the library and refactor angular-hal to work with it ?

@maennchen
Copy link
Contributor

Yes, exactly. And maybe also write a test for it.

@maennchen maennchen changed the title Troubles trying to make it work Content Type parsing error Mar 17, 2016
@maennchen maennchen added the bug label Mar 17, 2016
@maennchen maennchen added this to the v2.0 stable milestone Mar 17, 2016
@skol-pro
Copy link
Contributor Author

Ok why not, you have to know that it will be my first time contributing, but I'm really glad to ! :-)

@skol-pro
Copy link
Contributor Author

So, I've created a simple module + factory, but actually I'm just wondering 3 things:

  • No node modules folder, could you describe me how you would install the content-type lib ?
  • Should I let you create the minified version or is it on contributors shoulders to do this ? If so, how do you proceed ?
  • Still not really used to testing. If you do some, I would appreciate, so that I can check what you did !

I quite simply "duplicated" url-generator module & factory to create that, so, no-brain. I wouldn't be surprised if you tell me it's total bull**** :p

As I said, first time contributing, not used to all this stuff, and I'm really happy to be able to learn & contribute :)

@maennchen maennchen self-assigned this Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants