badgateway / ketting

The HATEOAS client for javascript
https://www.npmjs.com/package/ketting
MIT License
548 stars 32 forks source link

Problem responses don't allow (easy) access to the type field #332

Closed sazzer closed 3 years ago

sazzer commented 3 years ago

RFC-7807 defines 5 standard fields for a Problem Response:

It also allows other arbitrary fields to be provided as well.

The Ketting definition of a Problem only allows for the title field to be easily accessed, with the others all relatively awkward to get to - especially when using Typescript.

I can work around it but it's not pleasant:

console.log("Problem Response", (e.body as Record<string, any>).type);

At the very least, it would be nice if the class made access to the other fields easier. Even better would be a way to access the additional fields as well, and to have support for default values too - the type field should be considered to be about:blank if it's omitted, for example.

"type" (string) When this member is not present, its value is assumed to be "about:blank". https://tools.ietf.org/html/rfc7807#section-3.1

Cheers

evert commented 3 years ago

I think this hasn't really been touched since forever. It looks like the type was written to make Typescript pass (probably when I did the typescript conversion), but it wasn't made to be actually 'good' =)

So yea, worth doing...