mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
better error handler
This commit is contained in:
parent
f2ce280264
commit
08bf3a289f
2
.vscode/functions_schemas.code-snippets
vendored
2
.vscode/functions_schemas.code-snippets
vendored
@ -5,7 +5,7 @@
|
|||||||
"description": "Create a new functional core module with default schema for ycore-schema21",
|
"description": "Create a new functional core module with default schema for ycore-schema21",
|
||||||
"body": [
|
"body": [
|
||||||
"import verbosity from 'core/libs/verbosity'",
|
"import verbosity from 'core/libs/verbosity'",
|
||||||
"import { onError } from 'core/libs/errorhandler'",
|
"import handle from 'core/libs/errorhandler'",
|
||||||
"import { notify } from 'core/libs/appInterface'",
|
"import { notify } from 'core/libs/appInterface'",
|
||||||
"import settings from 'core/libs/settings'",
|
"import settings from 'core/libs/settings'",
|
||||||
"import endpoints from 'config/endpoints'",
|
"import endpoints from 'config/endpoints'",
|
||||||
|
9
config/handlers/errToFlag.js
Normal file
9
config/handlers/errToFlag.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
SESSION_INVALID: "DISRUPT",
|
||||||
|
OVERLAY_BADPOSITION: "IGNORE",
|
||||||
|
INTERNAL_PROCESS_FAILED: "CRITICAL",
|
||||||
|
INVALID_DATA: "DISRUPT",
|
||||||
|
INVALID_PROPS: "IGNORE",
|
||||||
|
MISSING_REQUIRED_PAYLOAD: "IGNORE"
|
||||||
|
}
|
||||||
|
|
9
config/handlers/errToStrings.js
Normal file
9
config/handlers/errToStrings.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
SESSION_INVALID: `Your session is invalid`,
|
||||||
|
OVERLAY_BADPOSITION: `Invalid overlay position! Was expected "primary" or "secondary"`,
|
||||||
|
INTERNAL_PROCESS_FAILED: `An internal error has occurred! `,
|
||||||
|
INVALID_DATA: `A function has been executed with invalid data and has caused an error!`,
|
||||||
|
INVALID_PROPS: `Some props failed!`,
|
||||||
|
MISSING_REQUIRED_PAYLOAD: "Error has occurred because the function needed data that does not exist"
|
||||||
|
}
|
||||||
|
|
9
config/handlers/numToError.js
Normal file
9
config/handlers/numToError.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
400: "SESSION_INVALID",
|
||||||
|
210: "OVERLAY_BADPOSITION",
|
||||||
|
110: "INTERNAL_PROCESS_FAILED",
|
||||||
|
120: "INVALID_DATA",
|
||||||
|
130: "INVALID_PROPS",
|
||||||
|
140: "MISSING_REQUIRED_PAYLOAD"
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ import { format } from 'timeago.js';
|
|||||||
import { cloneDeep } from 'lodash';
|
import { cloneDeep } from 'lodash';
|
||||||
import store from 'store';
|
import store from 'store';
|
||||||
import { i18n, app_config } from 'config';
|
import { i18n, app_config } from 'config';
|
||||||
import * as errorHandlers from 'core/libs/errorhandler'
|
import handle from 'core/libs/errorhandler'
|
||||||
import platform from 'platform'
|
import platform from 'platform'
|
||||||
import request from 'request'
|
import request from 'request'
|
||||||
import html2canvas from 'html2canvas'
|
import html2canvas from 'html2canvas'
|
||||||
@ -173,7 +173,7 @@ export function downloadDecodedURI(payload){
|
|||||||
tmp.download= filename
|
tmp.download= filename
|
||||||
tmp.click()
|
tmp.click()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorHandlers.onError.internal_proccess(error)
|
handle({ msg: error, code: 120 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ export function downloadEncodedURI(payload){
|
|||||||
tmp.download= filename
|
tmp.download= filename
|
||||||
tmp.click()
|
tmp.click()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorHandlers.onError.internal_proccess(error)
|
handle({ msg: error, code: 120 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,43 +1,66 @@
|
|||||||
import { appInterface } from 'core/libs'
|
import { appInterface } from 'core/libs'
|
||||||
import verbosity from 'core/libs/verbosity'
|
import verbosity from 'core/libs/verbosity'
|
||||||
|
import errStrings from 'config/handlers/errToStrings.js'
|
||||||
|
import errNumbers from 'config/handlers/numToError.js'
|
||||||
|
import errFlags from 'config/handlers/errToFlag.js'
|
||||||
|
|
||||||
// STRINGS
|
export function ErrorHandler(payload, callback){
|
||||||
export const OVERLAY_BADPOSITION = `Invalid overlay position! Was expected "primary" or "secondary"`
|
if (!payload) {
|
||||||
export const INTERNAL_PROCESS_FAILED = `An internal error has occurred! `
|
|
||||||
export const INVALID_DATA = `A function has been executed with invalid data and has caused an error!`
|
|
||||||
export const INVALID_PROPS = `Some props failed!`
|
|
||||||
// HANDLERS
|
|
||||||
export const onError = {
|
|
||||||
internal_proccess: (...rest) => {
|
|
||||||
verbosity({...rest}, {
|
|
||||||
type: "error"
|
|
||||||
})
|
|
||||||
appInterface.notify.open({
|
|
||||||
message: INTERNAL_PROCESS_FAILED,
|
|
||||||
description:
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', margin: 'auto' }}>
|
|
||||||
<div style={{ margin: '10px 0' }}> {JSON.stringify(...rest)} </div>
|
|
||||||
</div>,
|
|
||||||
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
invalid_data: (error, expecting) => {
|
|
||||||
verbosity({error}, {
|
|
||||||
type: "error"
|
|
||||||
})
|
|
||||||
appInterface.notify.open({
|
|
||||||
message: 'Invalid Data',
|
|
||||||
description:
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', margin: 'auto' }}>
|
|
||||||
<div style={{ margin: '10px 0' }}> {INVALID_DATA} </div>
|
|
||||||
<div style={{ margin: '10px 0', color: '#333' }}>
|
|
||||||
<h4>Expected: {expecting}</h4>
|
|
||||||
<h4 style={{ backgroundColor: 'rgba(221, 42, 42, 0.8)' }} >{`${error}`} </h4>
|
|
||||||
</div>
|
|
||||||
</div>,
|
|
||||||
|
|
||||||
})
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
const flagToString = {
|
||||||
|
CRITICAL: "An critical exception",
|
||||||
|
DISRUPT: "An wild error appears!",
|
||||||
|
IGNORE: "Warning"
|
||||||
|
}
|
||||||
|
|
||||||
|
const flags = ["CRITICAL", "DISRUPT", "IGNORE"]
|
||||||
|
let flag = null
|
||||||
|
let out = null
|
||||||
|
|
||||||
|
const { msg, outFlag, code } = payload
|
||||||
|
|
||||||
|
if (!out && code != null) { // This give priority to resolve with `code` than `outFlag`
|
||||||
|
out = errNumbers[code]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!out && outFlag != null ) {
|
||||||
|
out = outFlag
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out && typeof(errStrings[out]) !== "undefined") {
|
||||||
|
verbosity(msg, {type: "error"})
|
||||||
|
flag = errFlags[out]
|
||||||
|
}else{
|
||||||
|
console.log("(Aborted) no out key | or invalid flag => ", out)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
appInterface.notify.open({
|
||||||
|
message: flagToString[flag] ?? "Unexpected Error",
|
||||||
|
description:
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', margin: 'auto', height: "auto" }}>
|
||||||
|
<div style={{ margin: '10px 0' }}> {msg ?? "No exception message"} </div>
|
||||||
|
<div> => {errStrings[out] ?? "Unhandled Exception"} | { out?? "UNDEFINED_KEY" } </div>
|
||||||
|
</div>,
|
||||||
|
})
|
||||||
|
|
||||||
|
switch (flag) {
|
||||||
|
case flags[0]:
|
||||||
|
console.log("FLAG => ", flags[0])
|
||||||
|
return false
|
||||||
|
case flags[1]:
|
||||||
|
console.log("FLAG => ", flags[1])
|
||||||
|
return false
|
||||||
|
case flags[2]:
|
||||||
|
console.log("FLAG => ", flags[2])
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
console.log('Invalid FLAG')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default ErrorHandler
|
@ -1,7 +1,7 @@
|
|||||||
import store from 'store';
|
import store from 'store';
|
||||||
import { app_config } from 'config';
|
import { app_config } from 'config';
|
||||||
import verbosity from 'core/libs/verbosity'
|
import verbosity from 'core/libs/verbosity'
|
||||||
import * as errorHandlers from 'core/libs/errorhandler'
|
import ErrorHandler from 'core/libs/errorhandler'
|
||||||
|
|
||||||
const { appTheme_desiredContrast, appTheme_container } = app_config
|
const { appTheme_desiredContrast, appTheme_container } = app_config
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ export const theme = {
|
|||||||
try {
|
try {
|
||||||
raw.forEach((e)=>{container[e.key] = e.value})
|
raw.forEach((e)=>{container[e.key] = e.value})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorHandlers.onError.invalid_data(error, "ThemeScheme")
|
return ErrorHandler({ msg: error, code: 120 })
|
||||||
}
|
}
|
||||||
return container
|
return container
|
||||||
},
|
},
|
||||||
@ -104,7 +104,7 @@ export function getImagePixelColorsUsingCanvas(canvas, image) {
|
|||||||
try {
|
try {
|
||||||
imagePixelColors = ctx.getImageData(...destinationCanvasCoordinates);
|
imagePixelColors = ctx.getImageData(...destinationCanvasCoordinates);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorHandlers.onError.internal_proccess(error)
|
return ErrorHandler({ msg: error, code: 120 })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imagePixelColors) {
|
if (imagePixelColors) {
|
||||||
|
@ -4,7 +4,7 @@ import * as antd from 'antd'
|
|||||||
import {connect} from 'umi'
|
import {connect} from 'umi'
|
||||||
import styles from './index.less'
|
import styles from './index.less'
|
||||||
|
|
||||||
import { onError } from 'core/libs/errorhandler'
|
import ErrorHandler from 'core/libs/errorhandler'
|
||||||
import { theme, getOptimalOpacityFromIMG, get_style_rule_value } from 'core/libs/style'
|
import { theme, getOptimalOpacityFromIMG, get_style_rule_value } from 'core/libs/style'
|
||||||
import { urlToBase64, imageToBase64, arrayToObject } from 'core'
|
import { urlToBase64, imageToBase64, arrayToObject } from 'core'
|
||||||
import exportDataAsFile from 'core/libs/appInterface/export_data'
|
import exportDataAsFile from 'core/libs/appInterface/export_data'
|
||||||
@ -19,7 +19,7 @@ class ThemeConfigurator extends React.Component{
|
|||||||
applyStoraged(){
|
applyStoraged(){
|
||||||
const storaged = theme.get()
|
const storaged = theme.get()
|
||||||
if(storaged && this.state){
|
if(storaged && this.state){
|
||||||
storaged[this.state.key]? this.setState({ model: storaged[this.state.key]}) : onError.internal_proccess(`"Config key" or "Dispatcher" is missing`)
|
storaged[this.state.key]? this.setState({ model: storaged[this.state.key]}) : ErrorHandler({ msg: `"Config key" or "Dispatcher" is missing`, code: 140 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class ThemeConfigurator extends React.Component{
|
|||||||
|
|
||||||
handleUpdate(payload){
|
handleUpdate(payload){
|
||||||
if(!this.state.key || !this.props.dispatch) {
|
if(!this.state.key || !this.props.dispatch) {
|
||||||
return onError.internal_proccess(`"Config key" or "App/Dispatcher" is missing`)
|
return ErrorHandler({ msg: `"Config key" or "App/Dispatcher" is missing`, code: 140 })
|
||||||
}
|
}
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
payload = this.state.model
|
payload = this.state.model
|
||||||
|
Loading…
x
Reference in New Issue
Block a user