Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9274d0b

Browse files
committed
add error handling to web app
1 parent34f8059 commit9274d0b

File tree

8 files changed

+50
-15
lines changed

8 files changed

+50
-15
lines changed

‎web-app/src/components/Error/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ApolloError } from 'apollo-boost'
22
import{GraphQLError}from'graphql'
33
import*asReactfrom'react'
44
import{css,jsx}from'@emotion/core'
5+
importonErrorfrom'services/sentry/onError'
56

67
conststyles={
78
container:{
@@ -16,7 +17,12 @@ interface Props {
1617
}
1718

1819
constErrorView=({ error}:Props)=>{
19-
console.log(error)
20+
// log error
21+
React.useEffect(()=>{
22+
console.log(error)
23+
onError(error)
24+
},[])
25+
2026
return(
2127
<divcss={styles.container}>
2228
<h1>Error</h1>

‎web-app/src/components/ErrorBoundary/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import*asReactfrom'react'
2+
importonErrorfrom'../../services/sentry/onError'
23

34
classErrorBoundaryextendsReact.Component{
4-
publicstate={hasError:false}
5+
publicstate={errorMessage:null}
56

67
publiccomponentDidCatch(error:Error,info:any){
8+
onError(error)
79
// Display fallback UI
8-
this.setState({hasError:true})
10+
this.setState({errorMessage:error.message})
911
// You can also log the error to an error reporting service
1012
console.error(JSON.stringify(error))
1113
console.log(JSON.stringify(info))
1214
}
1315

1416
publicrender(){
15-
if(this.state.hasError){
17+
if(this.state.errorMessage){
1618
// You can render any custom fallback UI
17-
return<h1>Something went wrong.</h1>
19+
return<h1>{this.state.errorMessage}</h1>
1820
}
1921
returnthis.props.children
2022
}

‎web-app/src/components/Markdown/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import markdownEmoji from 'markdown-it-emoji'
44
//@ts-ignore no types for package
55
importprismfrom'markdown-it-prism'
66
import*asReactfrom'react'
7+
importonErrorfrom'../../services/sentry/onError'
78
// load prism styles & language support
89
import'./prism'
910

@@ -56,7 +57,9 @@ const Markdown = (props: Props) => {
5657
try{
5758
html=md.render(props.children)
5859
}catch(error){
59-
console.log(`failed to parse markdown for${props.children}`)
60+
constmessage=`failed to parse markdown for${props.children}`
61+
onError(newError(message))
62+
console.log(message)
6063
html=`<div style='background-color: #FFB81A; padding: 0.5rem;'>
6164
<strong style='padding-bottom: 0.5rem;'>ERROR: Failed to parse markdown</strong>
6265
<p>${props.children}</p>

‎web-app/src/components/Router/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import machine from '../../services/state/machine'
66
import{useMachine}from'../../services/xstate-react'
77
importdebuggerWrapperfrom'../Debugger/debuggerWrapper'
88
importRoutefrom'./Route'
9+
importonErrorfrom'services/sentry/onError'
910

1011
interfaceProps{
1112
children:any
@@ -45,7 +46,9 @@ const Router = ({ children }: Props): React.ReactElement<CloneElementProps> | nu
4546
returndebuggerWrapper(element,state)
4647
}
4748
}
48-
console.warn(`No Route matches for${JSON.stringify(state)}`)
49+
constmessage=`No Route matches for${JSON.stringify(state)}`
50+
onError(newError(message))
51+
console.warn(message)
4952
returnnull
5053
}
5154

‎web-app/src/services/selectors/tutorial.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import{createSelector}from'reselect'
22
import{MachineContext}from'typings'
33
import*asGfrom'typings/graphql'
4+
importonErrorfrom'services/sentry/onError'
45

56
exportconstcurrentTutorial=({ tutorial}:MachineContext):G.Tutorial=>{
67
if(!tutorial){
7-
thrownewError('Tutorial not found')
8+
consterror=newError('Tutorial not found')
9+
onError(error)
10+
throwerror
811
}
912
returntutorial
1013
}
1114

1215
exportconstcurrentVersion=createSelector(currentTutorial,(tutorial:G.Tutorial)=>{
1316
if(!tutorial.version){
14-
thrownewError('Tutorial version not found')
17+
consterror=newError('Tutorial version not found')
18+
onError(error)
19+
throwerror
1520
}
1621
returntutorial.version
1722
})
@@ -26,7 +31,9 @@ export const currentLevel = (context: MachineContext): G.Level =>
2631

2732
constlevelIndex=levels.findIndex((l:G.Level)=>l.id===context.position.levelId)
2833
if(levelIndex<0){
29-
thrownewError('Level not found when selecting level')
34+
consterror=newError(`Level not found when selecting level for${version}`)
35+
onError(error)
36+
throwerror
3037
}
3138
constlevel:G.Level=levels[levelIndex]
3239

@@ -41,7 +48,9 @@ export const currentStep = (context: MachineContext): G.Step =>
4148
conststeps:G.Step[]=level.steps
4249
conststep:G.Step|undefined=steps.find((s:G.Step)=>s.id===context.position.stepId)
4350
if(!step){
44-
thrownewError('No Step found')
51+
consterror=newError(`No Step found for Level${level.id}. Expected step${context.position.stepId}`)
52+
onError(error)
53+
throwerror
4554
}
4655
returnstep
4756
},

‎web-app/src/services/state/actions/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import client from '../../apollo'
44
import{setAuthToken}from'../../apollo/auth'
55
importauthenticateMutationfrom'../../apollo/mutations/authenticate'
66
importchannelfrom'../../channel'
7+
importonErrorfrom'services/sentry/onError'
78

89
interfaceAuthenticateData{
910
editorLogin:{
@@ -30,6 +31,7 @@ export default {
3031
},
3132
})
3233
.catch(error=>{
34+
onError(error)
3335
console.error('ERROR: Authentication failed')
3436
console.error(error)
3537
})

‎web-app/src/services/state/actions/context.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as CR from 'typings'
22
import*asGfrom'typings/graphql'
33
import{assign,send}from'xstate'
44
import*asselectorsfrom'../../selectors'
5+
importonErrorfrom'services/sentry/onError'
56

67
exportdefault{
78
setEnv:assign({
@@ -147,7 +148,9 @@ export default {
147148
// has next level?
148149

149150
if(!context.tutorial){
150-
thrownewError('Tutorial not found')
151+
consterror=newError('Tutorial not found')
152+
onError(error)
153+
throwerror
151154
}
152155

153156
constlevels=context.tutorial.version.data.levels||[]

‎web-app/src/services/state/actions/editor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import client from '../../apollo'
44
importtutorialQueryfrom'../../apollo/queries/tutorial'
55
importchannelfrom'../../channel'
66
import*asselectorsfrom'../../selectors'
7+
importonErrorfrom'services/sentry/onError'
78

89
interfaceTutorialData{
910
tutorial:G.Tutorial
@@ -30,7 +31,9 @@ export default {
3031
initializeTutorial(context:CR.MachineContext,event:CR.MachineEvent){
3132
// setup test runner and git
3233
if(!context.tutorial){
33-
thrownewError('Tutorial not available to load')
34+
consterror=newError('Tutorial not available to load')
35+
onError(error)
36+
throwerror
3437
}
3538

3639
client
@@ -43,7 +46,9 @@ export default {
4346
})
4447
.then(result=>{
4548
if(!result||!result.data||!result.data.tutorial){
46-
returnPromise.reject('No tutorial returned from tutorial config query')
49+
constmessage='No tutorial returned from tutorial config query'
50+
onError(newError(message))
51+
returnPromise.reject(message)
4752
}
4853

4954
channel.editorSend({
@@ -52,7 +57,9 @@ export default {
5257
})
5358
})
5459
.catch((error:Error)=>{
55-
returnPromise.reject(`Failed to load tutorial config${error.message}`)
60+
constmessage=`Failed to load tutorial config${error.message}`
61+
onError(newError(message))
62+
returnPromise.reject(message)
5663
})
5764
},
5865
continueConfig(context:CR.MachineContext){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp