Experiencing hell while dealing with tRPC procedures and the "input needs to be an object"... help
This is just a project that uses FB IG Graph API to retrieve information about the user and sends that to an endpoint. I googled and tried different approaches and I still can't see what is wrong.
I have also checked that returning typeof(input) results in "object" so I cannot understand why tRPC is not validating it as an object.
Also, I don't know why, but if I change the url to another url I get no trouble at all. This just has been driving me crazy the past few days trying to figure it out... Any help extremely appreciated!
Solution:Jump to solution
hey @peterkyle01
In case anyone struggles with this in the future... I figured it out. It all lies on this line of code:
In case anyone struggles with this in the future... I figured it out. It all lies on this line of code:
const response = await axios.post($env.URL, input, axiosConfig)
that needs to be await axios.post($env.URL, input, axiosConfig)
without awaiting the response to assign it to a variable. If it is approached that way then it works just fine (idk why, just fixed the bug)....10 Replies
you can try passing the input at the axios.post as an object like:
axios.post($env.URL, { input }, axiosConfig);
yep, tried that, even passing it as an array, as an object inside an a array and a destructured object too.. no luck. I just can't udnerstand why is it complaining.
Can you try console logging the input before sending it to axios to see its state ,then try sending a plain object like { foo:"bar"} to axios and see if it works
after trying I can confirm the bug is within the try catch block. I can see the input as an object logging before making the request. I am debuggin that part to try to achieve the request in some other way
Okay, lemme know if you find it
narrowed it down up to the request. for some reason that tRPC procedudre is unable to do any requests regardless of the input handling, it just keeps spamming the same error. I am creating a new procedure to test and compare
Okay,also look at how you call the procedure from the client
After breaking my balls a little bit with it I can confirm the error happens when a tRPC procedure tries to make a axios request either post or get with input parameters. This is something I do not understand because I am doing the same process to send that information to fb API Graph.
And then read the response from FB. It just does not make sense
Solution
hey @peterkyle01
In case anyone struggles with this in the future... I figured it out. It all lies on this line of code:
In case anyone struggles with this in the future... I figured it out. It all lies on this line of code:
const response = await axios.post($env.URL, input, axiosConfig)
that needs to be await axios.post($env.URL, input, axiosConfig)
without awaiting the response to assign it to a variable. If it is approached that way then it works just fine (idk why, just fixed the bug).Awsome ,thanks for the info 👌