-
|
Is it possible to define custom error classes and throw them over the wire? Take your authentication example: authenticate() could throw an AuthenticationFailedError, and the client can catch this to show a login form. Currently it doesn't work, the client receives a generic Error object. The docs confirm this: only "Error and its well-known subclasses are passed as-is" |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
In general, we intentionally do not support custom pass-by-value types. All custom types must be pass-by-reference. This includes custom Error subclasses. The reason for this is because custom serializable types have proven to be a security disaster in Java and other languages. It's just too easy to create a custom serializable type which inadvertently allows an attacker to trick the remote party into doing unsafe things, by sending an instance of that type when it isn't expected. What we can do, though, is:
I had intended to do both of these things but it looks like it's still marked as a TODO in the code. With all that said, I would probably recommend having |
Beta Was this translation helpful? Give feedback.
-
|
Yes I see what you mean. Thanks for replying! |
Beta Was this translation helpful? Give feedback.
In general, we intentionally do not support custom pass-by-value types. All custom types must be pass-by-reference. This includes custom Error subclasses.
The reason for this is because custom serializable types have proven to be a security disaster in Java and other languages. It's just too easy to create a custom serializable type which inadvertently allows an attacker to trick the remote party into doing unsafe things, by sending an instance of that type when it isn't expected.
What we can do, though, is:
error.nameto match the custom type ("AuthenticationFailedError") even if the class becomes justError.