-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve client error handling [Part 1] (#940)
* feature(#723): Improve client error handling [Part 1] This PR sets up the initial reducer/master plumbing for error handling by introducing a "transients" option bag containing errors. The goal of this change is to be as backwards-compatible as possible, with subsequent changes building on top of the API extensions added here. Notes: - Previously, there was an assumption that the state resulting from a reducer processing an action is suitable for client consumption. - Now, transient artifacts might be appended onto the state and need to be stripped before being sent to the client. - To work around this change, I added some new types to help signal the "transient" nature of State that enters and exits the reducer. - I'm assuming the master is the single caller of the core reducer and leaving it up to the master to do this stripping. * XXXSQUASHXXX: Iterate on PR feedback (3). - Fix typo in error codes - Fix typo in optional type. - Strip transients early in the reducer, obviating type changes to the plugins/main code. - Unify the re-dispatch-on-transient pattern between master and client with a new middleware. - Fix some fragile tests (See #941). - Narrow client/master test changes for new functionality. Left some TODO/dev notes for things to be done in subsequent PRs for #723 and for hypothetical future discussion. - Remove currently unused ActionResult to avoid extraneous diffs. * Expand union type to include undefined Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * Update error types for action_invalid. Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
- Loading branch information
Showing
11 changed files
with
415 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2017 The boardgame.io Authors | ||
* | ||
* Use of this source code is governed by a MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
export enum UpdateErrorType { | ||
// The action’s credentials were missing or invalid | ||
UnauthorizedAction = 'update/unauthorized_action', | ||
// The action’s matchID was not found | ||
MatchNotFound = 'update/match_not_found', | ||
// Could not apply Patch operation (rfc6902). | ||
PatchFailed = 'update/patch_failed', | ||
} | ||
|
||
export enum ActionErrorType { | ||
// The action contained a stale state ID | ||
StaleStateId = 'action/stale_state_id', | ||
// The requested move is unknown or not currently available | ||
UnavailableMove = 'action/unavailable_move', | ||
// The move declared it was invalid (INVALID_MOVE constant) | ||
InvalidMove = 'action/invalid_move', | ||
// The player making the action is not currently active | ||
InactivePlayer = 'action/inactive_player', | ||
// The game has finished | ||
GameOver = 'action/gameover', | ||
// The requested action is disabled (e.g. undo/redo, events) | ||
ActionDisabled = 'action/action_disabled', | ||
// The requested action is not currently possible | ||
ActionInvalid = 'action/action_invalid', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.