Closed watson closed 3 years ago
attributes
seems to only concern the unauthorized
boom error: https://github.com/hapijs/boom/blob/b25ee43255b939a28e99bae697bb82f73c0e8129/lib/index.js#L141 in latest version but also in 7.4.11
as far as I can tell . The typings seems to also reflect that in the latest version but not in the deprecated @types/hapi__boom
package. If you look in the comments on @types/hapi__boom
it's mentioned that way as well.
From what I can see you benefited from an error in the typings which has now been fixed since v8. It is unlikely that this will go back to how it was. One thing I'm curious though is: how did get data into badRequest().output.payload.attributes
?
I'll close this for now but we can continue to discuss this and we can reopen it if I made a mistake.
how did get data into
badRequest().output.payload.attributes
?
We simply manually populated the property:
However, this might not have been a good idea. I'm currently investigating why as I didn't write that code
After a bit of digging, I found that the hapi documentation actually allow the use of error.output.payload.any_custom_property
: https://hapi.dev/api/?v=20.0.3#error-transformation
Populating error.output.payload
with custom properties seem to be the only reasonable way to have the JSON http response populated with custom properties besides statusCode
, error
, and message
.
So shouldn't this also be allowed by TypeScript?
The boom types should be updated to handle this. I expect a [key: string]: unknown
property on the Payload
interface should do the trick.
I agree with @kanongil. Do you want to make a PR for it @watson?
PR: #279
Support plan
Context
What are you trying to achieve or the steps to reproduce?
What was the result you got?
TypeScript will complain about the last line with the following error:
What result did you expect?
No complaint from TypeScript.
In 7.4.11 we used
@types/hapi__boom
which did expose theattributes
property onPayload
. However, since v8.0.0 types have been built in to this package directly, but thePayload
object doesn't have any mention of anattributes
property.