@@ -12,7 +12,6 @@ import {findPreviousApplicableStep} from 'components/utils';
12
12
import useFormContext from 'hooks/useFormContext' ;
13
13
import useRefreshSubmission from 'hooks/useRefreshSubmission' ;
14
14
import useTitle from 'hooks/useTitle' ;
15
- import Types from 'types' ;
16
15
17
16
import GenericSummary from './GenericSummary' ;
18
17
import { loadSummaryData } from './utils' ;
@@ -21,6 +20,17 @@ const initialState = {
21
20
error : '' ,
22
21
} ;
23
22
23
+ const completeSubmission = async ( submission , statementValues ) => {
24
+ const response = await post ( `${ submission . url } /_complete` , statementValues ) ;
25
+ if ( ! response . ok ) {
26
+ console . error ( response . data ) ;
27
+ // TODO Specific error for each type of invalid data?
28
+ throw new Error ( 'InvalidSubmissionData' ) ;
29
+ } else {
30
+ return response . data ;
31
+ }
32
+ } ;
33
+
24
34
const reducer = ( draft , action ) => {
25
35
switch ( action . type ) {
26
36
case 'ERROR' : {
@@ -53,10 +63,8 @@ const SubmissionSummary = ({processingError = '', onConfirm, onClearProcessingEr
53
63
const submissionUrl = new URL ( refreshedSubmission . url ) ;
54
64
return await loadSummaryData ( submissionUrl ) ;
55
65
} , [ refreshedSubmission . url ] ) ;
56
-
57
- if ( error ) {
58
- console . error ( error ) ;
59
- }
66
+ // throw to nearest error boundary
67
+ if ( error ) throw error ;
60
68
61
69
const onSubmit = async statementValues => {
62
70
if ( refreshedSubmission . submissionAllowed !== SUBMISSION_ALLOWED . yes ) return ;
@@ -82,17 +90,6 @@ const SubmissionSummary = ({processingError = '', onConfirm, onClearProcessingEr
82
90
navigate ( getPreviousPage ( ) ) ;
83
91
} ;
84
92
85
- const completeSubmission = async ( submission , statementValues ) => {
86
- const response = await post ( `${ submission . url } /_complete` , statementValues ) ;
87
- if ( ! response . ok ) {
88
- console . error ( response . data ) ;
89
- // TODO Specific error for each type of invalid data?
90
- throw new Error ( 'InvalidSubmissionData' ) ;
91
- } else {
92
- return response . data ;
93
- }
94
- } ;
95
-
96
93
const pageTitle = intl . formatMessage ( {
97
94
description : 'Summary page title' ,
98
95
defaultMessage : 'Check and confirm' ,
0 commit comments