traverson / halfred

A parser for application/hal+json
MIT License
50 stars 5 forks source link

Halfred can't parse Resources with null embeds #34

Open gcaseres opened 5 years ago

gcaseres commented 5 years ago

Describe the bug When trying to parse a Resource returned from a remote API with null embedded resources, halfred reports an error: TypeError: "embeddedElement is null"

It looks like the problem could be solved by adding an if statement in line 73 of parser.js. I can send the PR if needed.

I understand that having a null value for an embedded resource could not be the best option for a HAL API, but I couldn't find any good argument against having null values. (for example, some uninitialized embed that will be populated later).

To Reproduce Just parsing a Resource with null values will raise the Error:

{
    "_embedded": {
        "embed": null
    }
}

Expected behavior The parsing process should accomplish without errors. When querying for the value of "embed", it should return null.

Node.js (please complete the following information):

samhiddenhand commented 5 years ago

I ran into this issue too while using the Vimeo VHX/OTT API

samhiddenhand commented 5 years ago

This is actually creating quite a blocker for me. I'm trying to follow() links and embeds in the Vimeo api using Traverson-hal, but some items contain the specified element, and some don't, so once it finds a null one, it errors out and doesn't parse the api. Help!