-
Notifications
You must be signed in to change notification settings - Fork 316
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
Fixes for Error Handling #231
base: master
Are you sure you want to change the base?
Changes from 15 commits
7912a20
b343bb4
dc3b237
502edd9
ba157db
7a07a54
1125fdd
ef53abc
6d82dc8
788accd
8709dfa
d44c80e
9bc5c7b
c03e431
8c9b3e2
e6eefe5
72b76f7
38799e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ class NgrokClient { | |
constructor(processUrl) { | ||
this.internalApi = got.extend({ | ||
prefixUrl: processUrl, | ||
retry: 0, | ||
retry: 3, | ||
}); | ||
} | ||
|
||
|
@@ -28,20 +28,12 @@ class NgrokClient { | |
} | ||
} catch (error) { | ||
let clientError; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couple of things here:
Could we do something like this: // .. defined above
function getResponse(error) {
if (error.response && error.response.body) {
let response;
try {
response = JSON.parse(error.response.body);
} catch (e) {
throw new NgrokClientError(e.msg, e.details);
}
return response;
}
return error;
}
// ... then
const response = getResponse(error);
throw new NgrokClientError(error.msg, error.details, response);
// ... and
} catch (e) {
const response = getResponse(e);
throw new NgrokClientError(e.msg, e.response, response);
}
|
||
try { | ||
const response = JSON.parse(error.response.body); | ||
clientError = new NgrokClientError( | ||
response.msg, | ||
error.response, | ||
const response = error.response ? error.response.body ? JSON.parse(error.response.body) : error.response : error; | ||
clientError = new NgrokClientError( | ||
error.msg, | ||
error.details, | ||
response | ||
); | ||
} catch (e) { | ||
clientError = new NgrokClientError( | ||
error.response.body, | ||
error.response, | ||
error.response.body | ||
); | ||
} | ||
); | ||
throw clientError; | ||
} | ||
} | ||
|
@@ -51,9 +43,9 @@ class NgrokClient { | |
return await this.internalApi[method](path, { json: options }).then( | ||
(response) => response.statusCode === 204 | ||
); | ||
} catch (error) { | ||
const response = JSON.parse(error.response.body); | ||
throw new NgrokClientError(response.msg, error.response, response); | ||
} catch (e) { | ||
const response = e.response ? e.response.body ? JSON.parse(e.response.body) : e.response : e | ||
throw new NgrokClientError(e.msg, e.response, response); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,7 @@ function validate(opts) { | |
} | ||
|
||
function isRetriable(err) { | ||
if (!err.response) { | ||
return false; | ||
} | ||
const statusCode = err.response.statusCode; | ||
const statusCode = err.response ? err.response.statusCode : err.body? err.body.status_code : 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the situation in which there was no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can tell, this doesn't come from changes to the NgrokClient. This change was made because I was receiving errors in the error handling that should have gone through the retry logic but didn't because of this problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that one of the unit tests dealing with paid plans is broken now, it looks like this needs further investigation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem occurs when someone has a paid plan and it's in use on another machine. In other words, a tunnel cannot be created because only one tunnel is allowed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd put this in a separate PR personally |
||
const body = err.body; | ||
const notReady500 = statusCode === 500 && /panic/.test(body); | ||
const notReady502 = | ||
|
@@ -47,7 +44,7 @@ function isRetriable(err) { | |
statusCode === 503 && | ||
body.details && | ||
body.details.err === | ||
"a successful ngrok tunnel session has not yet been established"; | ||
"a successful ngrok tunnel session has not yet been established"; | ||
return notReady500 || notReady502 || notReady503; | ||
} | ||
|
||
|
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.
With retries from
got
and retries based on theisRetriable
function we have two different ways that retries might happen. Is there a reason to include retries fromgot
specifically?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.
Okay, makes sense to put this back to 0.