@@ -20,12 +20,17 @@ import {
20
20
Typography ,
21
21
} from '@mui/material' ;
22
22
import { red } from '@mui/material/colors' ;
23
- import { LanguageData } from 'types/course/assessment/question/programming' ;
23
+ import {
24
+ LanguageData ,
25
+ PackageImportResultError ,
26
+ } from 'types/course/assessment/question/programming' ;
24
27
25
28
import GlobalAPI from 'api' ;
26
29
import buildFormData from 'course/assessment/question/programming/commons/builder' ;
30
+ import { ImportResultErrorMapper } from 'course/assessment/question/programming/components/common/ImportResult' ;
27
31
import {
28
32
create ,
33
+ fetchImportResult ,
29
34
update ,
30
35
} from 'course/assessment/question/programming/operations' ;
31
36
import { generationActions as actions } from 'course/assessment/reducers/generation' ;
@@ -60,7 +65,7 @@ const translations = defineMessages({
60
65
} ,
61
66
exportError : {
62
67
id : 'course.assessment.generation.exportError' ,
63
- defaultMessage : 'An error occured in exporting this question. ' ,
68
+ defaultMessage : 'An error occured in exporting this question: {error} ' ,
64
69
} ,
65
70
} ) ;
66
71
@@ -84,6 +89,26 @@ const GenerateExportDialog: FC<Props> = (props) => {
84
89
) ;
85
90
} ;
86
91
92
+ const handleExportError = async (
93
+ conversation : ConversationState ,
94
+ exportErrorMessage ?: string ,
95
+ ) : Promise < void > => {
96
+ let exportError = PackageImportResultError . GENERIC_ERROR ;
97
+ if ( conversation . questionId ) {
98
+ const importResult = await fetchImportResult ( conversation . questionId ) ;
99
+ exportError = importResult . error ?? exportError ;
100
+ // exportErrorMessage in arguments will take precedence, in case a new error happens somewhere other than the import job.
101
+ exportErrorMessage = exportErrorMessage ?? importResult . message ;
102
+ }
103
+ dispatch (
104
+ actions . exportConversationError ( {
105
+ conversationId : conversation . id ,
106
+ exportError,
107
+ exportErrorMessage,
108
+ } ) ,
109
+ ) ;
110
+ } ;
111
+
87
112
const pollQuestionExportJobs = ( ) : void => {
88
113
Object . values ( generatePageData . conversations )
89
114
. filter (
@@ -102,19 +127,11 @@ const GenerateExportDialog: FC<Props> = (props) => {
102
127
} ) ,
103
128
) ;
104
129
} else if ( response . data . status === 'errored' ) {
105
- dispatch (
106
- actions . exportConversationError ( {
107
- conversationId : conversation . id ,
108
- } ) ,
109
- ) ;
130
+ handleExportError ( conversation ) ;
110
131
}
111
132
} )
112
133
. catch ( ( error ) => {
113
- dispatch (
114
- actions . exportConversationError ( {
115
- conversationId : conversation . id ,
116
- } ) ,
117
- ) ;
134
+ handleExportError ( conversation , error . message ) ;
118
135
} ) ;
119
136
} ) ;
120
137
} ;
@@ -128,6 +145,20 @@ const GenerateExportDialog: FC<Props> = (props) => {
128
145
} ;
129
146
} ) ;
130
147
148
+ const exportErrorMessage = ( conversation : ConversationState ) : string => {
149
+ if (
150
+ ! conversation . exportError ||
151
+ conversation . exportError === PackageImportResultError . GENERIC_ERROR
152
+ ) {
153
+ return t ( translations . exportError , {
154
+ error : conversation . exportErrorMessage ?? '' ,
155
+ } ) ;
156
+ }
157
+ // We reuse the same error messages as the main programming question page,
158
+ // though the user should never see INVALID_PACKAGE error because it's entirely managed by us.
159
+ return t ( ImportResultErrorMapper [ conversation . exportError ] ) ;
160
+ } ;
161
+
131
162
return (
132
163
< Dialog
133
164
className = "top-10"
@@ -203,7 +234,7 @@ const GenerateExportDialog: FC<Props> = (props) => {
203
234
/>
204
235
{ conversation . exportStatus === 'error' && (
205
236
< Typography color = { red [ 700 ] } variant = "caption" >
206
- { t ( translations . exportError ) }
237
+ { exportErrorMessage ( conversation ) }
207
238
</ Typography >
208
239
) }
209
240
</ section >
@@ -286,11 +317,7 @@ const GenerateExportDialog: FC<Props> = (props) => {
286
317
}
287
318
} )
288
319
. catch ( ( error ) => {
289
- dispatch (
290
- actions . exportConversationError ( {
291
- conversationId : conversation . id ,
292
- } ) ,
293
- ) ;
320
+ handleExportError ( conversation , error . message ) ;
294
321
} ) ;
295
322
} ) ;
296
323
} }
0 commit comments