halfred icon indicating copy to clipboard operation
halfred copied to clipboard

Halfred can't parse Resources with null embeds

Open gcaseres opened this issue 6 years ago • 2 comments

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):

  • OS: Ubuntu 18
  • Node.js version: 10.14.1
  • Halfred Version: 1.1.0

gcaseres avatar Dec 10 '18 21:12 gcaseres

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

samhiddenhand avatar Dec 12 '18 11:12 samhiddenhand

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!

samhiddenhand avatar Jan 09 '19 07:01 samhiddenhand