mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 23:42:41 +00:00
error logging to vault
This commit is contained in:
@@ -161,7 +161,7 @@ const errorIndex = (props)=>{
|
|||||||
Please login or signup at our [login page](https://www.naturalcrit.com/login?redirect=https://homebrewery.naturalcrit.com/account).`,
|
Please login or signup at our [login page](https://www.naturalcrit.com/login?redirect=https://homebrewery.naturalcrit.com/account).`,
|
||||||
|
|
||||||
// Brew locked by Administrators error
|
// Brew locked by Administrators error
|
||||||
'100' : dedent`
|
'51' : dedent`
|
||||||
## This brew has been locked.
|
## This brew has been locked.
|
||||||
|
|
||||||
Only an author may request that this lock is removed.
|
Only an author may request that this lock is removed.
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const NewBrew = require('../../navbar/newbrew.navitem.jsx');
|
|||||||
const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
||||||
const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx');
|
const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx');
|
||||||
const SplitPane = require('../../../../shared/naturalcrit/splitPane/splitPane.jsx');
|
const SplitPane = require('../../../../shared/naturalcrit/splitPane/splitPane.jsx');
|
||||||
|
const ErrorIndex = require('../errorPage/errors/errorIndex.js');
|
||||||
|
|
||||||
const request = require('../../utils/request-middleware.js');
|
const request = require('../../utils/request-middleware.js');
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ const VaultPage = (props) => {
|
|||||||
window.history.replaceState(null, null, url);
|
window.history.replaceState(null, null, url);
|
||||||
};
|
};
|
||||||
|
|
||||||
const performSearch = async ({ title, author, count, v3, legacy }) => {
|
const performSearch = async ({ title, author, count, v3, legacy, page }) => {
|
||||||
updateUrl(title, author, count, v3, legacy, page);
|
updateUrl(title, author, count, v3, legacy, page);
|
||||||
console.log(title, author, count, v3, legacy);
|
console.log(title, author, count, v3, legacy);
|
||||||
if ((title || author) && (v3 || legacy)) {
|
if ((title || author) && (v3 || legacy)) {
|
||||||
@@ -84,7 +85,6 @@ const VaultPage = (props) => {
|
|||||||
|
|
||||||
const loadTotal = async ({ title, v3, legacy }) => {
|
const loadTotal = async ({ title, v3, legacy }) => {
|
||||||
setTotalBrews(null);
|
setTotalBrews(null);
|
||||||
setError(null);
|
|
||||||
if ((title || author) && (v3 || legacy)) {
|
if ((title || author) && (v3 || legacy)) {
|
||||||
const response = await request.get(
|
const response = await request.get(
|
||||||
`/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}`
|
`/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}`
|
||||||
@@ -117,17 +117,17 @@ const VaultPage = (props) => {
|
|||||||
const v3 = v3Ref.current.checked != false;
|
const v3 = v3Ref.current.checked != false;
|
||||||
const legacy = legacyRef.current.checked != false;
|
const legacy = legacyRef.current.checked != false;
|
||||||
|
|
||||||
console.log(title);
|
|
||||||
if (update) {
|
if (update) {
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
setAuthor(author);
|
setAuthor(author);
|
||||||
setCount(count);
|
setCount(count);
|
||||||
setV3(v3);
|
setV3(v3);
|
||||||
setLegacy(legacy);
|
setLegacy(legacy);
|
||||||
|
setPage(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform search with the latest input values, because state is not fast enough
|
// Perform search with the latest input values, because state is not fast enough
|
||||||
performSearch({ title, author, count, v3, legacy });
|
performSearch({ title, author, count, v3, legacy, page });
|
||||||
|
|
||||||
if (total) {
|
if (total) {
|
||||||
loadTotal({ title, author, v3, legacy });
|
loadTotal({ title, author, v3, legacy });
|
||||||
@@ -359,27 +359,12 @@ const VaultPage = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
const errorText = ErrorIndex({ brew })[brew.HBErrorCode.toString()] || '';
|
||||||
console.log('render Error: ', error);
|
console.log('render Error: ', error);
|
||||||
let errorMessage;
|
|
||||||
switch (error.errorCode) {
|
|
||||||
case '404':
|
|
||||||
errorMessage = "404 - We didn't find any brew";
|
|
||||||
break;
|
|
||||||
case '503':
|
|
||||||
errorMessage =
|
|
||||||
'503 - Service Unavailable, try again later, sorry.';
|
|
||||||
break;
|
|
||||||
case '500':
|
|
||||||
errorMessage =
|
|
||||||
"500 - We don't know what happened, go ahead and contact the mods or report as a mistake.";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errorMessage = 'An unexpected error occurred';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="foundBrews noBrews">
|
<div className="foundBrews noBrews">
|
||||||
<h3>Error: {errorMessage}</h3>
|
<h3>Error: {errorText}</h3>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ const api = {
|
|||||||
stub = stub?.toObject();
|
stub = stub?.toObject();
|
||||||
|
|
||||||
if(stub?.lock?.locked && accessType != 'edit') {
|
if(stub?.lock?.locked && accessType != 'edit') {
|
||||||
throw { HBErrorCode: '100', code: stub.lock.code, message: stub.lock.shareMessage, brewId: stub.shareId, brewTitle: stub.title };
|
throw { HBErrorCode: '51', code: stub.lock.code, message: stub.lock.shareMessage, brewId: stub.shareId, brewTitle: stub.title };
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a google id, try to find the google brew
|
// If there is a google id, try to find the google brew
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ describe('Tests for api', ()=>{
|
|||||||
const req = { brew: {} };
|
const req = { brew: {} };
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
await expect(fn(req, null, next)).rejects.toEqual({ 'HBErrorCode': '100', 'brewId': '1', 'brewTitle': 'test brew', 'code': 404, 'message': 'brew locked' });
|
await expect(fn(req, null, next)).rejects.toEqual({ 'HBErrorCode': '51', 'brewId': '1', 'brewTitle': 'test brew', 'code': 404, 'message': 'brew locked' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user