sazz
sazz
SIASapphire - Imagine a framework
Created by sazz on 9/2/2024 in #sapphire-support
Fetch not calling JSON.stringify for body objects.
Hey, i'm currently using @sapphire/fetch and trying to send a POST request for a API with a object on the body. The thing is: the object is not being stringified and the API is receiving [object Object]. I went through the @sapphire/fetch source code and, apparently, the function that determines if a body should be stringified or not (shouldJsonStringify) is returning false for my object. (https://github.com/sapphiredev/utilities/blob/main/packages/fetch/src/lib/fetch.ts#L191-L208) And just to make it clear, the object that i'm trying to send is in fact...a object, because using typeof theObject returns object lol, but its doesn't have a toJSON function or a Object constructor, in fact it has a [Function: Object] constructor, which is not included in the shouldJsonStringify function. Hope that this is enough information, happy to create a issue or maybe create a pull request with a fix. Downgrading the lib to 3.0.2 is my workaround for now.
14 replies