fix(plugins/developer-kit): proper error message for websocket disconnects
This commit is contained in:
parent
5d379b1652
commit
13ffdbca90
3 changed files with 21 additions and 29 deletions
|
|
@ -7,7 +7,6 @@ import { getBridgeInfo } from '@revenge-mod/modules/native'
|
||||||
import { instead } from '@revenge-mod/patcher'
|
import { instead } from '@revenge-mod/patcher'
|
||||||
import { noop } from '@revenge-mod/utils/callback'
|
import { noop } from '@revenge-mod/utils/callback'
|
||||||
import { lookupGeneratedIconComponent } from '@revenge-mod/utils/discord'
|
import { lookupGeneratedIconComponent } from '@revenge-mod/utils/discord'
|
||||||
import { getErrorStack } from '@revenge-mod/utils/error'
|
|
||||||
import { useReRender } from '@revenge-mod/utils/react'
|
import { useReRender } from '@revenge-mod/utils/react'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { api } from '.'
|
import { api } from '.'
|
||||||
|
|
@ -96,23 +95,20 @@ export function connect() {
|
||||||
events.emit('connect')
|
events.emit('connect')
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.addEventListener('close', () => {
|
ws.addEventListener('close', e_ => {
|
||||||
cleanup()
|
cleanup()
|
||||||
events.emit('disconnect')
|
events.emit('disconnect')
|
||||||
})
|
|
||||||
|
|
||||||
ws.addEventListener('error', e => {
|
const e = e_ as CloseEvent
|
||||||
cleanup()
|
if (!e.wasClean) {
|
||||||
events.emit('errored', e)
|
api.logger.error('DevTools error:', e.reason)
|
||||||
|
|
||||||
const err = (e as { message: string }).message ?? getErrorStack(e)
|
ToastActionCreators.open({
|
||||||
api.logger.error('DevTools error:', err)
|
key: 'DEVTOOLS_ERROR',
|
||||||
|
IconComponent: CircleErrorIcon,
|
||||||
ToastActionCreators.open({
|
content: e.reason,
|
||||||
key: 'DEVTOOLS_ERROR',
|
})
|
||||||
IconComponent: CircleErrorIcon,
|
}
|
||||||
content: err,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { ToastActionCreators } from '@revenge-mod/discord/actions'
|
import { ToastActionCreators } from '@revenge-mod/discord/actions'
|
||||||
import { TypedEventEmitter } from '@revenge-mod/discord/common/utils'
|
import { TypedEventEmitter } from '@revenge-mod/discord/common/utils'
|
||||||
import { lookupGeneratedIconComponent } from '@revenge-mod/utils/discord'
|
import { lookupGeneratedIconComponent } from '@revenge-mod/utils/discord'
|
||||||
import { getErrorStack } from '@revenge-mod/utils/error'
|
|
||||||
import { useReRender } from '@revenge-mod/utils/react'
|
import { useReRender } from '@revenge-mod/utils/react'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { api } from '.'
|
import { api } from '.'
|
||||||
|
|
@ -40,23 +39,20 @@ export function connect() {
|
||||||
events.emit('connect')
|
events.emit('connect')
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.addEventListener('close', () => {
|
ws.addEventListener('close', e_ => {
|
||||||
cleanup()
|
cleanup()
|
||||||
events.emit('disconnect')
|
events.emit('disconnect')
|
||||||
})
|
|
||||||
|
|
||||||
ws.addEventListener('error', e => {
|
const e = e_ as CloseEvent
|
||||||
cleanup()
|
if (!e.wasClean) {
|
||||||
events.emit('errored', e)
|
api.logger.error('React DevTools error:', e.reason)
|
||||||
|
|
||||||
const err = (e as { message: string }).message ?? getErrorStack(e)
|
ToastActionCreators.open({
|
||||||
api.logger.error('React DevTools error:', err)
|
key: 'REACT_DEVTOOLS_ERROR',
|
||||||
|
IconComponent: CircleErrorIcon,
|
||||||
ToastActionCreators.open({
|
content: e.reason,
|
||||||
key: 'REACT_DEVTOOLS_ERROR',
|
})
|
||||||
IconComponent: CircleErrorIcon,
|
}
|
||||||
content: err,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
__REACT_DEVTOOLS__!.exports.connectToDevTools({
|
__REACT_DEVTOOLS__!.exports.connectToDevTools({
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["ESNext"],
|
"lib": ["ESNext", "DOM"],
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue