Describe the bug
After https://github.com/PLhery/node-twitter-api-v2/pull/254 you could call the v2.search method with just an options object instead of a string for the query and an optional options object. But the query provided in the options objects is:
Unintentionally overridden by undefined, leading to a 400 from Twitter, and
Unenforced by Typescript even though it's required by the Twitter API
To Reproduce
Please indicate all steps that lead to this bug:
Create client with read access
Query v2.search using just an options object with a query key. For example:
Expected behavior
Query completes without throwing
Actual behavior
Query throws 400 error response from twitter:
Request failed with code 400, data: {
errors: [
{
parameters: [Object],
message: 'The `query` query parameter can not be empty'
}
],
title: 'Invalid Request',
detail: 'One or more parameters to your request was invalid.',
type: 'https://api.twitter.com/2/problems/invalid-request'
}
Version
Node.js 16.15.0
Lib version 1.13.0
MacOS Monterey
Additional context
The alternative API using just an options object instead of a query stringand an options object was implemented in response to this issue: https://github.com/PLhery/node-twitter-api-v2/issues/252
I think it's worth considering reverting the original change to the API. It makes the code more complex and wasn't really related to the original issue. The original API made enforcement of having a query value very clear with a very clear type error. My PR also enforces it but the type error is much harder to read.
Describe the bug After https://github.com/PLhery/node-twitter-api-v2/pull/254 you could call the
v2.search
method with just an options object instead of astring
for the query and an optional options object. But thequery
provided in the options objects is:undefined
, leading to a400
from Twitter, andTo Reproduce Please indicate all steps that lead to this bug:
read
accessQuery
v2.search
using just an options object with aquery
key. For example:Expected behavior Query completes without throwing
Actual behavior Query throws
400
error response from twitter:Version
Additional context The alternative API using just an options object instead of a query
string
and an options object was implemented in response to this issue: https://github.com/PLhery/node-twitter-api-v2/issues/252 I think it's worth considering reverting the original change to the API. It makes the code more complex and wasn't really related to the original issue. The original API made enforcement of having aquery
value very clear with a very clear type error. My PR also enforces it but the type error is much harder to read.