import { fetchEventSource } from '@microsoft/fetch-event-source' const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run' // class PermissionError extends Error { } export default (url, { onmessage, onerror, controller, params, onopen }) => { const token = useCookie('token') fetchEventSource(`${BASE_URL}${url}`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': '*/*', 'Authorization': token.value }, body: JSON.stringify(params), onopen (response) { const status = response.status useRequestError(status) onopen(status) // todo // if ([401, 403].includes(status)) { // throw new PermissionError(); // } }, onmessage (info) { onmessage(info) }, onerror (error) { onerror(error) }, openWhenHidden: true, signal: controller && controller.signal }) }