chore: Simplify proxy logging flow
MODIFY
lib/jsonwp-proxy/proxy.js
lib/jsonwp-proxy/proxy.js
@@ -204,20 +204,16 @@ class JWProxy {
// We only consider an error unexpected if this was not
// an async request module error or if the response cannot be cast to
// a valid JSON
- if (!util.hasValue(e.error)) {
+ if (util.hasValue(e.error)) {
+ if (!isResponseLogged) {
+ const error = truncateBody(e.error);
+ log.info(util.hasValue(e.statusCode)
+ ? `Got response with status ${e.statusCode}: ${error}`
+ : `Got response with unknown status: ${error}`);
+ }
+ } else {
log.warn(e.message);
log.debug(e.stack);
- } else {
- if (!util.hasValue(e.statusCode) || !/^\s*\{/.test(e.error)) {
- if (isResponseLogged) {
- log.info('The response has an unknown format');
- } else {
- log.info(`Got an unexpected response with status ${e.statusCode}: ${truncateBody(e.error)}`);
- }
- } else if (!isResponseLogged) {
- log.debug(`Got response with status ${e.statusCode}: ${truncateBody(e.error)}`);
- isResponseLogged = true;
- }
}
throw new errors.ProxyRequestError(`Could not proxy command to remote server. ` +
`Original error: ${e.message}`, e.error, e.statusCode);

chore: Simplify proxy logging flow (#389)