Skip to content

Commit

Permalink
Merge pull request #268 from woodja/bugfix/fix-defaults
Browse files Browse the repository at this point in the history
Fix JS issues / increase error usefulness
  • Loading branch information
moficodes authored Apr 20, 2022
2 parents c7c01cd + cd049dc commit 57d49a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions lib/archiving.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ' + JSON.stringify(body)));
}
}
else {
Expand Down Expand Up @@ -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: ' + JSON.stringify(body)));
}
}
else if (body.status !== 'started') {
callback(new errors.RequestError('Unexpected response from OpenTok'));
callback(new errors.RequestError('Unexpected response from OpenTok: ' + JSON.stringify(body)));
}
else {
callback(null, new Archive(config, body));
Expand Down Expand Up @@ -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: ' + JSON.stringify(body)));
}
}
else {
Expand Down Expand Up @@ -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: ' + JSON.stringify(body)));
}
}
else {
Expand All @@ -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
};
}
Expand All @@ -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: ' + JSON.stringify(body)));
}
else if (response && response.statusCode === 403) {
callback(new errors.AuthError('Invalid API key or secret'));
Expand All @@ -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: ' + JSON.stringify(body)));
}
}
else {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'));
Expand All @@ -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: ' + JSON.stringify(body)));
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions spec/opentok_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 57d49a7

Please sign in to comment.