-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/trn 28/improve network errors #83
Conversation
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.
Code review only, I'll test a bit later.
Question from StackOverflow: since we're compiling with Babel, do we need to have babel-plugin-transform-builtin-extend
to make this work?
src/core/error/ApiError.js
Outdated
/** | ||
* Instantiate an error | ||
* @param {string} message- the error message | ||
* @param {number} errorCode - the HTTP status or custom error code |
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.
It looks fairly standard, but isn't this mixing 2 concepts? If TAO would one day have custom error codes, such as E42 - bad QTI response format
, should they be stored in the same field which can be 500 - Server Error
?
Suggestion: keep errorCode
and httpStatusCode
apart.
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.
Yes, I think it's the reason why we use errorCode
and not status
. The status is already available in response.status
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.
Ok then is the comment accurate for the intended usage? (the HTTP status or custom error code
)
.catch(err => { | ||
if(!err.type){ | ||
//offline, CORS, etc. | ||
return Promise.reject(new NetworkError(err.message, 0)); |
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.
Thought: what does errorCode: 0
mean?
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.
https://fetch.spec.whatwg.org/#concept-network-error 0 means a network error: the request has not reached the server for various reason (no internet, no route, not allowed by CORS, etc.)
it looks like the current version of Babel handles it correctly, ie |
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.
Looks good, please check the comments on updates/suggestions
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, ApiError); | ||
} |
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've seen in other implementations fallback to this.stack = (new Error()).stack
if Error.captureStackTrace
is not supported
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.
Error.captureStackTrace
is only used in node.js (so the stack trace appears in the unit tests when failing).
By default, the stack will be captured by inheriting from the Error
type, it is generated by the constructor. The implementation should be identical cross browser once handled by Babel.
After some research on the question of custom error https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types. The main point is to ensure extra parameters to the parent constructor because some browsers will have a |
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.
Tests are passing and it's working integrated to https://github.com/oat-sa/tao-deliver-testrunner-nui-fe/pull/102
- New code is covered by tests (if applicable)
- Tests are running successfully (old and new ones) on my local machine (if applicable)
- New code is respecting code style rules
- New code is respecting best practices
- New code is not subject to concurrency issues (if applicable)
- Feature is working correctly on my local machine (if applicable)
- Acceptance criteria are respected
- Pull request title and description are meaningful
- Pull request's target is not
master
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.
- New code is covered by tests (if applicable)
- Tests are running successfully (old and new ones) on my local machine (if applicable)
- New code is respecting code style rules
- New code is respecting best practices
- New code is not subject to concurrency issues (if applicable)
- Feature is working correctly on my local machine (if applicable)
- Acceptance criteria are respected
- Pull request title and description are meaningful
* @param {boolean} [recoverable=true] - can the user recover after having such error ? | ||
* @param {...} params - additional error parameters (line, etc.) | ||
*/ | ||
constructor(message, errorCode, response, recoverable = true, ...params) { |
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.
It looks correct API-wise, but since there is no standard, I didn't see how we could ever benefit from the extra ...params
passed through.
As you said, in Firefox they map onto properties like lineNumber
, fileName
, but it's proprietary, Safari doesn't do anything with such params.
Related to https://oat-sa.atlassian.net/browse/TRN-28
TimeoutError
,ApiError
andNetworkError
incore/fetchRequest
How to test: