@tpzdsp/next-toolkit 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/http.ts +12 -1
package/package.json
CHANGED
package/src/utils/http.ts
CHANGED
|
@@ -128,10 +128,21 @@ const post = <Ok, Error = ApiFailure>(
|
|
|
128
128
|
body: unknown,
|
|
129
129
|
options?: RequestInit,
|
|
130
130
|
): Promise<Response<Ok, Error>> => {
|
|
131
|
+
let requestBody: string;
|
|
132
|
+
|
|
133
|
+
// If body is an empty object, send an empty string
|
|
134
|
+
if (body && typeof body === 'object' && !Array.isArray(body) && Object.keys(body).length === 0) {
|
|
135
|
+
requestBody = '';
|
|
136
|
+
} else if (body === undefined || body === null) {
|
|
137
|
+
requestBody = '{}';
|
|
138
|
+
} else {
|
|
139
|
+
requestBody = JSON.stringify(body);
|
|
140
|
+
}
|
|
141
|
+
|
|
131
142
|
const requestOptions = {
|
|
132
143
|
...options,
|
|
133
144
|
method: HttpMethod.Post,
|
|
134
|
-
body:
|
|
145
|
+
body: requestBody,
|
|
135
146
|
headers: {
|
|
136
147
|
'Content-Type': MimeTypes.Json,
|
|
137
148
|
...options?.headers,
|