Add ApiException class for proper Error inheritance #115
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Replace plain
ApiErrorobjects withApiExceptionclass that extendsError, so error handlers can properly display the message.Problem
The previous implementation threw plain objects
{statusCode, message}. When these objects were caught by error handlers (webpack-dev-server overlay, browser console), they were displayed as[object Object]instead of the actual error message.Solution
1. ApiException class
Features:
Error→ proper.message,.stack,toString()ApiError→ backward compatibleObject.setPrototypeOf→ ES5 prototype chain fix2. Network error handling
3. API error handling with fallbacks
Edge cases handled:
{"statusCode": 400, "message": "Error"}{"error": "Bad"}["error"]"string"nullTest Plan
Network error: Failed to fetcherror.statusCodeworkserror.messageworkserror instanceof Error→trueerror instanceof ApiException→true