From 86587e7715567af02992d223c8e2e9ef2d0b3c9f Mon Sep 17 00:00:00 2001 From: Jason Wood Date: Thu, 14 Apr 2022 14:06:17 -0400 Subject: [PATCH 1/4] Fix JS issues / increase error usefulness --- lib/archiving.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/archiving.js b/lib/archiving.js index eb45a27d..2c1d22ff 100644 --- a/lib/archiving.js +++ b/lib/archiving.js @@ -233,7 +233,7 @@ exports.listArchives = function (config, options, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError('Unexpected response from OpenTok')); + callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); } } else { @@ -291,11 +291,11 @@ exports.startArchive = function (ot, config, sessionId, options, callback) { callback(new errors.ArchiveError('Recording already in progress or session not using OpenTok Media Router')); } else { - callback(new errors.RequestError('Unexpected response from OpenTok')); + callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); } } else if (body.status !== 'started') { - callback(new errors.RequestError('Unexpected response from OpenTok')); + callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); } else { callback(null, new Archive(config, body)); @@ -332,7 +332,7 @@ exports.stopArchive = function (config, archiveId, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError('Unexpected response from OpenTok')); + callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); } } else { @@ -372,7 +372,7 @@ exports.getArchive = function (config, archiveId, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError('Unexpected response from OpenTok')); + callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); } } else { @@ -393,8 +393,8 @@ function patchArchive(config, archiveId, options, callback) { if (options.addStream && options.addStream.length > 0) { options = { - hasAudio: options.hasAudio || true, - hasVideo: options.hasVideo || true, + hasAudio: options.hasAudio ?? true, + hasVideo: options.hasVideo ?? true, addStream: options.addStream }; } @@ -412,10 +412,10 @@ function patchArchive(config, archiveId, options, callback) { 'PATCH', '/archive/' + encodeURIComponent(archiveId) + '/streams', options, - function patchArchiveCallback(err, response) { + function patchArchiveCallback(err, response, body) { if (err || response.statusCode !== 200) { if (response && response.statusCode === 400) { - callback(new errors.ArgumentError('Invalid request')); + callback(new errors.ArgumentError(`Invalid request: ${body}`)); } else if (response && response.statusCode === 403) { callback(new errors.AuthError('Invalid API key or secret')); @@ -427,7 +427,7 @@ function patchArchive(config, archiveId, options, callback) { callback(new errors.ArchiveError('Unsupported Stream Mode')); } else { - callback(new errors.RequestError('Unexpected response from OpenTok')); + callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); } } else { @@ -456,8 +456,8 @@ exports.addArchiveStream = function (config, archiveId, streamId, archiveOptions archiveOptions = { addStream: streamId, - hasAudio: archiveOptions.hasAudio || true, - hasVideo: archiveOptions.hasVideo || true + hasAudio: archiveOptions.hasAudio ?? true, + hasVideo: archiveOptions.hasVideo ?? true }; patchArchive(config, archiveId, archiveOptions, callback); @@ -492,7 +492,7 @@ exports.deleteArchive = function (config, archiveId, callback) { 'DELETE', '/archive/' + encodeURIComponent(archiveId), null, - function deleteArchiveCallback(err, response) { + function deleteArchiveCallback(err, response, body) { if (err || response.statusCode !== 204) { if (response && response.statusCode === 404) { callback(new errors.ArchiveError('Archive not found')); @@ -501,7 +501,7 @@ exports.deleteArchive = function (config, archiveId, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError('Unexpected response from OpenTok')); + callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); } } else { From ea0e954f0d3ed9f81ae028d85b505737c3dcbac0 Mon Sep 17 00:00:00 2001 From: Mofizur Rahman Date: Tue, 19 Apr 2022 12:51:30 -0400 Subject: [PATCH 2/4] linting fix --- lib/archiving.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/archiving.js b/lib/archiving.js index 2c1d22ff..4499d972 100644 --- a/lib/archiving.js +++ b/lib/archiving.js @@ -233,7 +233,7 @@ exports.listArchives = function (config, options, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); + callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body))); } } else { @@ -291,11 +291,11 @@ exports.startArchive = function (ot, config, sessionId, options, callback) { callback(new errors.ArchiveError('Recording already in progress or session not using OpenTok Media Router')); } else { - callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); + callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body))); } } else if (body.status !== 'started') { - callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); + callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body))); } else { callback(null, new Archive(config, body)); @@ -332,7 +332,7 @@ exports.stopArchive = function (config, archiveId, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); + callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body))); } } else { @@ -372,7 +372,7 @@ exports.getArchive = function (config, archiveId, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); + callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body))); } } else { @@ -393,8 +393,8 @@ function patchArchive(config, archiveId, options, callback) { if (options.addStream && options.addStream.length > 0) { options = { - hasAudio: options.hasAudio ?? true, - hasVideo: options.hasVideo ?? true, + hasAudio: options.hasAudio != null ? options.hasAudio : true, + hasVideo: options.hasVideo != null ? options.hasVideo : true, addStream: options.addStream }; } @@ -415,7 +415,7 @@ function patchArchive(config, archiveId, options, callback) { function patchArchiveCallback(err, response, body) { if (err || response.statusCode !== 200) { if (response && response.statusCode === 400) { - callback(new errors.ArgumentError(`Invalid request: ${body}`)); + callback(new errors.ArgumentError('Invalid request: ' + JSON.stringify(body))); } else if (response && response.statusCode === 403) { callback(new errors.AuthError('Invalid API key or secret')); @@ -427,7 +427,7 @@ function patchArchive(config, archiveId, options, callback) { callback(new errors.ArchiveError('Unsupported Stream Mode')); } else { - callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); + callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body))); } } else { @@ -456,8 +456,8 @@ exports.addArchiveStream = function (config, archiveId, streamId, archiveOptions archiveOptions = { addStream: streamId, - hasAudio: archiveOptions.hasAudio ?? true, - hasVideo: archiveOptions.hasVideo ?? true + hasAudio: archiveOptions.hasAudio != null ? archiveOptions.hasAudio : true, + hasVideo: archiveOptions.hasVideo != null ? archiveOptions.hasVideo : true }; patchArchive(config, archiveId, archiveOptions, callback); @@ -501,7 +501,7 @@ exports.deleteArchive = function (config, archiveId, callback) { callback(new errors.AuthError('Invalid API key or secret')); } else { - callback(new errors.RequestError(`Unexpected response from OpenTok: ${body}`)); + callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body))); } } else { From 93fc1a2054667c2b6ecb369631f373a84c8d0a78 Mon Sep 17 00:00:00 2001 From: Mofizur Rahman Date: Tue, 19 Apr 2022 13:26:02 -0400 Subject: [PATCH 3/4] update tests to check for body --- spec/opentok_spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/opentok_spec.js b/spec/opentok_spec.js index 86297545..6129af6b 100644 --- a/spec/opentok_spec.js +++ b/spec/opentok_spec.js @@ -169,7 +169,7 @@ describe('Archiving', function () { opentok.startArchive(mockSessionId, function (err) { expect(err).not.toBeNull(); - expect(err.message).toBe('Unexpected response from OpenTok'); + expect(err.message).toBe('Unexpected response from OpenTok: {"message":"responseString"}'); done(); }); }); @@ -375,7 +375,7 @@ describe('Archiving', function () { opentok.getArchive(mockArchiveId, function (err) { expect(err).not.toBeNull(); - expect(err.message).toBe('Unexpected response from OpenTok'); + expect(err.message).toBe('Unexpected response from OpenTok: {"message":"Something went wrong"}'); done(); }); }); @@ -459,7 +459,7 @@ describe('Archiving', function () { expect(archives).toBeUndefined(); expect(total).toBeUndefined(); expect(err).not.toBeNull(); - expect(err.message).toBe('Unexpected response from OpenTok'); + expect(err.message).toBe('Unexpected response from OpenTok: {"message":"Some error"}'); done(); }); }); @@ -604,7 +604,7 @@ describe('Archiving', function () { opentok.stopArchive(mockArchiveId, function (err, archive) { expect(archive).toBeUndefined(); expect(err).not.toBeNull(); - expect(err.message).toBe('Unexpected response from OpenTok'); + expect(err.message).toBe('Unexpected response from OpenTok: {"message":"Some other error."}'); done(); }); }); @@ -671,7 +671,7 @@ describe('Archiving', function () { opentok.deleteArchive(mockArchiveId, function (err) { expect(err).not.toBeNull(); - expect(err.message).toBe('Unexpected response from OpenTok'); + expect(err.message).toBe('Unexpected response from OpenTok: "{ \\"message\\" : \\"Some other error.\\" }"'); done(); }); }); From cd049dcac22784c1bb5482f7499a1f56be81dc55 Mon Sep 17 00:00:00 2001 From: Mofizur Rahman Date: Tue, 19 Apr 2022 13:33:00 -0400 Subject: [PATCH 4/4] update package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 237fb239..b7cc5e23 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "opentok", "description": "OpenTok server-side SDK", - "version": "2.14.1", + "version": "2.14.2", "homepage": "https://github.com/opentok/opentok-node", "repository": { "type": "git",