From e852c8925cbd656559e62e4e5d79de351ce26613 Mon Sep 17 00:00:00 2001 From: eroosenmaallen Date: Tue, 3 May 2022 09:59:07 -0400 Subject: [PATCH 1/2] * _doRestApiRequest: Properly attach request errors to err.allErrors * _doRestApiRequest: Attach full mastodonReply to err.mastodonReply to aid debugging * _buildReqOpts: for a POST request, put the encoded parameters into request.body instead of the request URL --- lib/mastodon.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/mastodon.js b/lib/mastodon.js index 67a23556..71002d73 100644 --- a/lib/mastodon.js +++ b/lib/mastodon.js @@ -161,7 +161,8 @@ Mastodon.prototype._buildReqOpts = function (method, path, params, callback) { try { // finalize the `path` value by building it using user-supplied params - path = helpers.moveParamsIntoPath(finalParams, path) + if (method === 'GET') + path = helpers.moveParamsIntoPath(finalParams, path) } catch (e) { callback(e, null, null) return @@ -182,7 +183,10 @@ Mastodon.prototype._buildReqOpts = function (method, path, params, callback) { } else { // Non-file-upload params should be url-encoded if (Object.keys(finalParams).length > 0) { - reqOpts.url += this.formEncodeParams(finalParams); + if (request === 'GET') + reqOpts.url += this.formEncodeParams(finalParams); + else + reqOpts.body = this.formEncodeParams(finalParams).replace(/^\?/, ''); } } @@ -214,7 +218,8 @@ Mastodon.prototype._doRestApiRequest = function (reqOpts, mastoOptions, method, // surface this to the caller var err = helpers.makeMastodonError('JSON decode error: Mastodon HTTP response body was not valid JSON') err.statusCode = response ? response.statusCode: null; - err.allErrors.concat({error: jsonDecodeError.toString()}) + err.allErrors.push({error: jsonDecodeError.toString()}); + err.mastodonReply = body; callback(err, body, response); return } From 4005425f1c9986d96855496d306625e20f5ed0aa Mon Sep 17 00:00:00 2001 From: eroosenmaallen Date: Wed, 4 May 2022 10:27:07 -0400 Subject: [PATCH 2/2] Fixed parameters-in-path --- lib/mastodon.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/mastodon.js b/lib/mastodon.js index 71002d73..edc86001 100644 --- a/lib/mastodon.js +++ b/lib/mastodon.js @@ -161,8 +161,7 @@ Mastodon.prototype._buildReqOpts = function (method, path, params, callback) { try { // finalize the `path` value by building it using user-supplied params - if (method === 'GET') - path = helpers.moveParamsIntoPath(finalParams, path) + path = helpers.moveParamsIntoPath(finalParams, path) } catch (e) { callback(e, null, null) return