Skip to content

Commit

Permalink
fix bug where errors would not show until restart
Browse files Browse the repository at this point in the history
  • Loading branch information
jmicko committed Jan 23, 2024
1 parent f51ca7f commit 89a1e6b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
18 changes: 11 additions & 7 deletions client/src/components/Messages/MessageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export function MessageSection({
}
}, [messages, initialRender, mobileCollapsed, header]);

console.log(messages, 'messages ' + header);


return (
(user.can_chat || header !== 'Chat') &&
Expand All @@ -70,12 +72,13 @@ export function MessageSection({
: 'expanded'} ` + header.split(' ').join('-').toLowerCase()}>


<h3 className={
`${(collapsed && !onMobile)
|| (mobileCollapsed !== header && mobileCollapsed !== '' && onMobile)
? 'collapsed'
: 'expanded'} title message-header ${user.theme}`
}
<h3
className={
`${(collapsed && !onMobile)
|| (mobileCollapsed !== header && mobileCollapsed !== '' && onMobile)
? 'collapsed'
: 'expanded'} title message-header ${user.theme}`
}
onClick={() => {
if (onMobile) {
if (mobileCollapsed === header) {
Expand All @@ -84,7 +87,7 @@ export function MessageSection({
console.log('setting mobile collapsed to ', header);
setMobileCollapsed && setMobileCollapsed(header)
}
}
} header
}}
>
{(collapsed && !onMobile) && messages.length} {header}
Expand All @@ -100,6 +103,7 @@ export function MessageSection({
})
}
<div className="spacer" />
{/* {JSON.stringify(messages)} */}
</div>}

{header === 'Chat' &&
Expand Down
3 changes: 3 additions & 0 deletions client/src/providers/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ export function DataProvider({ children }: { children: ReactNode }) {
refresh: refreshBotErrors,
} = useGetFetch<Messages>(botErrorsOptions)

console.log(botErrors, '< botErrors');


// ////////////////////////
// //////// ORDERS ////////
// ////////////////////////
Expand Down
13 changes: 11 additions & 2 deletions server/modules/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class Messenger {
this.instantMessage({ type: 'messageUpdate', messageUpdate: true })
}
// todo - should probably use type: 'error' and get rid of this
newError(err) {
async newError(err) {
try {
devLog(err.errorText);
const error = new Message({
Expand All @@ -360,7 +360,7 @@ class Messenger {
data: err.data ? err.data : null
});
if (error.text) {
const saved = saveMessage(this.userID, error);
const saved = await saveMessage(this.userID, error);
this.errors.unshift(saved);
}

Expand All @@ -379,6 +379,15 @@ class Messenger {
}
getErrors() {
return this.errors;
// const errors = [];

// this.messages.forEach(message => {
// // console.log(message, 'message');
// if (message.type === 'error') {
// errors.push(message);
// }
// });
// return errors;
}
clearErrors() {
this.errors.length = 0;
Expand Down
1 change: 1 addition & 0 deletions server/routes/account.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ router.get('/errors', rejectUnauthenticated, async (req, res) => {
const userID = req.user.id;
try {
const userErrors = messenger[userID].getErrors();
console.log(userErrors, '< userErrors');
res.send(userErrors);
} catch (err) {
devLog(err, 'problem debug route');
Expand Down

0 comments on commit 89a1e6b

Please sign in to comment.