42 lines
984 B
TypeScript
42 lines
984 B
TypeScript
import { parseApiErrorMessage } from '../../../packages/shared/src/http';
|
|
import { fetchWithApiAuth, requestJson } from '../apiClient';
|
|
|
|
export async function requestRpgCreationPostJson<T>(
|
|
url: string,
|
|
payload: unknown,
|
|
fallbackMessage: string,
|
|
) {
|
|
return requestJson<T>(
|
|
url,
|
|
{
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
},
|
|
fallbackMessage,
|
|
);
|
|
}
|
|
|
|
export async function openRpgCreationSsePost(
|
|
url: string,
|
|
payload: unknown,
|
|
fallbackMessage: string,
|
|
) {
|
|
const response = await fetchWithApiAuth(url, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const responseText = await response.text();
|
|
throw new Error(parseApiErrorMessage(responseText, fallbackMessage));
|
|
}
|
|
|
|
if (!response.body) {
|
|
throw new Error('streaming response body is unavailable');
|
|
}
|
|
|
|
return response;
|
|
}
|