-
Notifications
You must be signed in to change notification settings - Fork 142
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
What is the reason error property is boolean? #17
Comments
I think the reasoning might be so that you can serialize the action (which requires converting the Error object into a plain object) but still be able to convert the serialized action into its original state. |
Ah, OK. It is not a problem then. I was working on the Canonical Composition Action spec. If you do not require that object is an instance of Error and instead specify certain traits (e.g. it must have message property), then object can be serialised and unserialised as needed. By the way, I am happy if FSA copy from CCA everything. I am only trying to improve the standard. I have little hope for replacing the standard. |
+1 for error property being any object with a message property. You can serialise an Error object: JSON.stringify(new Error("my message"), ['message'])
// "{"message":"my message"}" You can even serialise the stack if you so wish... Having an error boolean flag to me seems like a duplication of action information. For example, an action sequence that performs a batch update with optimism. { type: BATCH_ITEM_UPDATE_PENDING, payload: {items[]}, meta: {actionId} }
{ type: BATCH_ITEM_UPDATE_SUCCESS, payload: {successful_item_ids[]}, meta: {actionId} }
{ type: BATCH_ITEM_UPDATE_FAIL, payload: {failed_items[]}, meta: {actionId} } The meta property contains an id specific to the action sequence -- not the state changes. |
I'm struggling a bit with this design as well. Our application has the typical pattern of fetches dispatching REQUEST, SUCCESS and FAILURE actions. For all of these actions, the payload always contains the contextual information required to identify which part of the state tree its for. If the FAILURE action is supposed to have the This is unless contextual information is always supposed to go into the |
Forcing the assignment of error to the payload property seems to force you to use custom error objects, that contain all necessary information to describe the error context. |
Which is a good thing.
|
I agree that It's good to enforce standards and common structures but I don't think the payload is the best place for that when handling an error action. Right now we already force the error field to be a boolean, which is clearly limited in the information it can communicate -- so seems like a better place to enforce custom error objects. Then the payload doesn't need to conform to a structure when in an error action and can be free to contain more data about the error-action. |
The error design of Flux Standard Actions is completely unworkable for us; we've decided to not use Flux Standard Actions for that reason.
|
Using an error flag is more explicit in term of what is possible with javascript. If you want to use a falsy value as your "error object"/payload you are unable to determine if your action is an error or not. Example:
|
@mlegenhausen -- you can have a falsy value in your payload if you conform to No-one here is suggesting that passing an empty string (or any other ambiguous falsy value) should be used as an error value. |
I agree with where this is going. If there's an error, it's in my action type & that action creator can handle the error. What I don't like is having the error itself in the payload instead of the action that caused the error (or the multiple failed items if it's a batch job). I say let error be an Error object & for those edge cases where the action type doesn't have an ERROR/FAIL suffix, they can |
I agree with the general sentiment of this issue. I personally am using something akin to Error Handling in Nodejs guidelines, where only ever one property of Anyway, I am sure there is an XKCD mentioning something about competing standards.... |
👍 I concur also. Ditch the boolean on the error attribute and store the error there. |
I came from SO for this same issue. When an error occurs, it IS an action. It is not an action with an error. I forsee conditional logic sprinkled all over your action handling code checking for an error property when you could simply be handling an error action. If you are using something like redux, you can have a dedicated reducer handling errors. A better design would have been to standardize the error payload so handling is streamlined. Another thing is properties that 'MAY' exist. How is that even standard then? More conditional logic for me. An action should have ONLY two properties. A TYPE and a PAYLOAD. Everything else, error messages, meta data etc should be in the PAYLOAD. That is a standard. |
Consider this ideal use case where an AJAX request has 3 prongs:
Wouldn't it make the most sense to have the payload consistent across all three in order to tell what parameters led to error / success? Unless I keep the original action in the action-creator scope, then put it in meta (yo dawg I heard you like actions), I cannot see what the payload of the initial action was. |
The parameters causing an error can be put into an Error object -- along with many other things. I would assume it's more common for server responses to be placed in payload, not the meta object -- which makes the payload inconsistent already. |
we can have a |
I think the original intent of adding {
type: 'ADD_TODO',
payload: {
text: 'Do something.'
}
}
{
type: 'ADD_TODO',
payload: new Error(),
error: true
} There are no redundancies in this example. Due to the way people use Redux, though, it starts to get redundant. {
type: 'ADD_TODO_REQUEST',
payload: {
text: 'Do something.'
}
}
{
type: 'ADD_TODO_SUCCESS',
payload: {
text: 'Do something.'
}
}
{
type: 'ADD_TODO_FAILURE',
payload: new Error(),
error: true
} Perhaps the correct approach would be to separate app concerns from asynchronous concerns and instead of doing The only issue this brings are optimistic updates. This could be solved, though, by triggering actions that queue the change when the request is made and then committing when it succeeds or reverting if it fails. |
Exactly my point. What happens when you decide that for a certain error, you want to do something different for example? You |
as opposed to an instance of
Error
object. Boolean flag is vague. It just says what the error is and does not standardise the method of getting error description. Docs say thatpayload
by convention should be anError
object.The text was updated successfully, but these errors were encountered: