diff --git a/src/APIFunctions/2DPrinting.js b/src/APIFunctions/2DPrinting.js index de570e43d..d72f911e1 100644 --- a/src/APIFunctions/2DPrinting.js +++ b/src/APIFunctions/2DPrinting.js @@ -89,8 +89,7 @@ export async function printPage(data, token) { body: data }); if (res.ok) { - const response = await res.json(); - status.responseData = response.message; + status.responseData = true; } } catch (err) { status.responseData = err; @@ -122,7 +121,7 @@ export async function getPagesPrinted(email, token) { }); if (res.ok) { const response = await res.json(); - status.pagesUsed = response.pagesUsed; + status.pagesUsed = response; } else { status.error = true; } diff --git a/src/APIFunctions/Messaging.js b/src/APIFunctions/Messaging.js index b2059192a..7fb04f0bf 100644 --- a/src/APIFunctions/Messaging.js +++ b/src/APIFunctions/Messaging.js @@ -1,28 +1,32 @@ -import axios from 'axios'; import { ApiResponse } from './ApiResponses'; import { BASE_API_URL } from '../Enums'; export async function sendMessage(id, token, message) { let status = new ApiResponse(); const roomId = id || 'general'; - const url = new URL('/api/messages/send', BASE_API_URL); - - await axios - .post(url.href, - { message, id: roomId }, - { - headers: { - 'authorization' : 'Bearer ' + token - } - }) - .then(res => { - status.responseData = res.data; - }) - .catch(err => { - status.error = true; - status.responseData = err; + try { + const res = await fetch(url.href, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + message, + id: roomId, + }), }); + if (res.ok) { + const result = await res.json(); + status.responseData = result; + } else { + status.error = true; + } + } catch(err) { + status.error = true; + status.responseData = error; + } return status; } @@ -44,4 +48,3 @@ export async function connectToRoom(room, token, onMessage, onError) { return eventSource; } -