-
Notifications
You must be signed in to change notification settings - Fork 26.6k
refactor(core): Support Error like object for resource errors. #62111
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
base: main
Are you sure you want to change the base?
Conversation
Error like object will be treated as errors. Related to angular#61861
2ad49e7
to
63e3d23
Compare
export function isErrorLike(error: unknown): error is Error { | ||
return ( | ||
error instanceof Error || | ||
(typeof error === 'object' && error !== null && 'message' in error && 'name' in error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the fix be instead to update this http error to properly extend Error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpErrorResponse
already extends another class.
angular/packages/common/http/src/response.ts
Line 339 in a40abf0
export class HttpErrorResponse extends HttpResponseBase implements Error { |
I think the change I'm suggesting has a much lower impact as we're already on the error code path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will defer to others. I don't have full context on why the encapsulation exists— but it sounds like the encapsulation tries to ensure it's an Error
, and this treats error-like objects as such, even though they aren't necessarily fully satisfying Error
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefacing this with: I'm not on the Angular team, but this is blocking an experimental branch of mine that prepares for the Angular 20 update (and beyond) - so I tried to dig around in what is publicly available. I hope my involvement on this issue is not too egregious.
"I don't have full context on why the encapsulation exists"
It seems as though the reason is of subjective nature.
Maybe @alxhub could shed some light on this?
Error like objects will be treated as errors.
Related to #61861