Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/APIFunctions/2DPrinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
39 changes: 21 additions & 18 deletions src/APIFunctions/Messaging.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -44,4 +48,3 @@ export async function connectToRoom(room, token, onMessage, onError) {

return eventSource;
}