Skip to content

Commit

Permalink
Merge pull request #490 from 1AhmedYasser/HotFix-Console-Error
Browse files Browse the repository at this point in the history
Hot Fix Console Error
  • Loading branch information
varmoh authored Apr 18, 2024
2 parents 876e62c + 4ae9ab3 commit 41df278
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions GUI/src/services/sse-service.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
const notificationNodeUrl = import.meta.env.REACT_APP_NOTIFICATION_NODE_URL;

const sse = <T>(url: string, onMessage: (data: T) => void): EventSource => {
if(!notificationNodeUrl) {
console.error('Notification node url is not defined')
if (!notificationNodeUrl) {
console.error('Notification node url is not defined');
throw new Error('Notification node url is not defined');
}
const eventSource = new EventSource(`${notificationNodeUrl}/sse/notifications${url}`);
const eventSource = new EventSource(
`${notificationNodeUrl}/sse/notifications${url}`
);

eventSource.onmessage = (event: MessageEvent) => {
if (event.data != undefined && event.data != "undefined") {
const response = JSON.parse(event.data);
if (response != undefined) {
onMessage(Object.values(response)[0] as T);
}
if (event.data != undefined && event.data != 'undefined') {
const response = JSON.parse(event.data);
if (response != undefined) {
onMessage(Object.values(response)[0] as T);
}
}
};

eventSource.onopen = () => {
console.log("SSE connection Opened");
console.log('SSE connection Opened');
};

eventSource.onerror = () => {
console.error('SSE error');
// console.error('SSE error, url:', url); // Uncomment this line to see the error in the console
};

return eventSource;
Expand Down

0 comments on commit 41df278

Please sign in to comment.