When a url given to the got.post / got.get functions is incorrect AND the function is followed with a .json(), this error is thrown:
TypeError: got.post(...).json is not a function
Error is thrown (see above)
Throw HTTP Error 404, Not found
function test(){
return got.get('undefined/https://jsonplaceholder.typicode.com/todos/1').json();
};
test();
Looks like when got attempts to normalize arguments it catches any thrown exceptions and can in some cases return a rejected Promise. Obviously this is a normal promise so it does not include any of the convenience methods that would usually be included (like json).
A possibly naive solution might be to just move the argument normalization outside of the try/catch. A better solution might be to make a decorator that can augment the rejected promise to include the convenience methods so that they also return a rejected promise.
I'd be happy to take this on, but I could use a little direction from a maintainer since I'm kind of new to this codebase.
In the as-promise.ts file export a function that would shim rejecting promises: let's call it createRejection:
const createRejection = (error: Error) => {
const promise = Promise.reject(error) as asPromise;
const returnPromise = () => promise;
promise.json = returnPromise;
promise.text = returnPromise;
promise.buffer = returnPromise;
promise.on = returnPromise;
return promise;
};