@@ -76,79 +76,72 @@ public UploadStatus processRequest(Context context, RequestParams params) {
7676
7777 ErrorInfo error = null ;
7878
79- if (errorCount < maxErrorRetries ) {
80- if (optionsLoadedSuccessfully ) {
81- if (StringUtils .isNotBlank (uri )) {
82- Payload payload = PayloadFactory .fromUri (uri );
83- if (payload != null ) {
84- try {
85- runningJobs .incrementAndGet ();
86- resultData = doProcess (requestId , appContext , options , params , payload );
87- requestResultStatus = SUCCESS ;
88- } catch (FileNotFoundException e ) {
89- Logger .e (TAG , String .format ("FileNotFoundException for request %s." , requestId ), e );
90- requestResultStatus = FAILURE ;
91- error = new ErrorInfo (ErrorInfo .FILE_DOES_NOT_EXIST , e .getMessage ());
92- } catch (LocalUriNotFoundException e ) {
93- Logger .e (TAG , String .format ("LocalUriNotFoundException for request %s." , requestId ), e );
94- requestResultStatus = FAILURE ;
95- error = new ErrorInfo (ErrorInfo .URI_DOES_NOT_EXIST , e .getMessage ());
96- } catch (ResourceNotFoundException e ) {
97- Logger .e (TAG , String .format ("ResourceNotFoundException for request %s." , requestId ), e );
98- error = new ErrorInfo (ErrorInfo .RESOURCE_DOES_NOT_EXIST , e .getMessage ());
99- requestResultStatus = FAILURE ;
100- } catch (EmptyByteArrayException e ) {
101- Logger .e (TAG , String .format ("EmptyByteArrayException for request %s." , requestId ), e );
102- requestResultStatus = FAILURE ;
103- error = new ErrorInfo (ErrorInfo .BYTE_ARRAY_PAYLOAD_EMPTY , e .getMessage ());
104- } catch (InterruptedIOException e ) {
105- Logger .e (TAG , String .format ("InterruptedIO exception for request %s." , requestId ), e );
106- error = new ErrorInfo (ErrorInfo .REQUEST_CANCELLED , "Request cancelled." );
107- requestResultStatus = FAILURE ;
108- } catch (ErrorRetrievingSignatureException e ) {
109- Logger .e (TAG , String .format ("Error retrieving signature for request %s." , requestId ), e );
110- requestResultStatus = FAILURE ;
111- error = new ErrorInfo (ErrorInfo .SIGNATURE_FAILURE , e .getMessage ());
112- } catch (IOException e ) {
113- Logger .e (TAG , String .format ("IOException for request %s." , requestId ), e );
79+ if (optionsLoadedSuccessfully ) {
80+ if (StringUtils .isNotBlank (uri )) {
81+ Payload payload = PayloadFactory .fromUri (uri );
82+ if (payload != null ) {
83+ try {
84+ runningJobs .incrementAndGet ();
85+ resultData = doProcess (requestId , appContext , options , params , payload );
86+ requestResultStatus = SUCCESS ;
87+ } catch (FileNotFoundException e ) {
88+ Logger .e (TAG , String .format ("FileNotFoundException for request %s." , requestId ), e );
89+ requestResultStatus = FAILURE ;
90+ error = new ErrorInfo (ErrorInfo .FILE_DOES_NOT_EXIST , e .getMessage ());
91+ } catch (LocalUriNotFoundException e ) {
92+ Logger .e (TAG , String .format ("LocalUriNotFoundException for request %s." , requestId ), e );
93+ requestResultStatus = FAILURE ;
94+ error = new ErrorInfo (ErrorInfo .URI_DOES_NOT_EXIST , e .getMessage ());
95+ } catch (ResourceNotFoundException e ) {
96+ Logger .e (TAG , String .format ("ResourceNotFoundException for request %s." , requestId ), e );
97+ error = new ErrorInfo (ErrorInfo .RESOURCE_DOES_NOT_EXIST , e .getMessage ());
98+ requestResultStatus = FAILURE ;
99+ } catch (EmptyByteArrayException e ) {
100+ Logger .e (TAG , String .format ("EmptyByteArrayException for request %s." , requestId ), e );
101+ requestResultStatus = FAILURE ;
102+ error = new ErrorInfo (ErrorInfo .BYTE_ARRAY_PAYLOAD_EMPTY , e .getMessage ());
103+ } catch (InterruptedIOException e ) {
104+ Logger .e (TAG , String .format ("InterruptedIO exception for request %s." , requestId ), e );
105+ error = new ErrorInfo (ErrorInfo .REQUEST_CANCELLED , "Request cancelled." );
106+ requestResultStatus = FAILURE ;
107+ } catch (ErrorRetrievingSignatureException e ) {
108+ Logger .e (TAG , String .format ("Error retrieving signature for request %s." , requestId ), e );
109+ requestResultStatus = FAILURE ;
110+ error = new ErrorInfo (ErrorInfo .SIGNATURE_FAILURE , e .getMessage ());
111+ } catch (IOException e ) {
112+ Logger .e (TAG , String .format ("IOException for request %s." , requestId ), e );
114113
115- if (errorCount >= maxErrorRetries ) {
116- // failure
117- error = getMaxRetryError (errorCount );
118- requestResultStatus = FAILURE ;
119- } else {
120- // one up error count and reschedule
121- params .putInt (ERROR_COUNT_PARAM , errorCount + 1 );
122- error = new ErrorInfo (ErrorInfo .NETWORK_ERROR , e .getMessage ());
123- requestResultStatus = RESCHEDULE ;
124- }
125- } catch (Exception e ) {
126- Logger .e (TAG , String .format ("Unexpected exception for request %s." , requestId ), e );
127- error = new ErrorInfo (ErrorInfo .UNKNOWN_ERROR , e .getMessage ());
114+ if (errorCount >= maxErrorRetries ) {
115+ // failure
116+ error = getMaxRetryError (errorCount );
128117 requestResultStatus = FAILURE ;
129- } finally {
130- runningJobs .decrementAndGet ();
118+ } else {
119+ // one up error count and reschedule
120+ params .putInt (ERROR_COUNT_PARAM , errorCount + 1 );
121+ error = new ErrorInfo (ErrorInfo .NETWORK_ERROR , e .getMessage ());
122+ requestResultStatus = RESCHEDULE ;
131123 }
132- } else {
133- Logger .d (TAG , String .format ("Failing request %s, payload cannot be loaded ." , requestId ));
134- error = new ErrorInfo (ErrorInfo .PAYLOAD_LOAD_FAILURE , "Request payload could not be loaded." );
124+ } catch ( Exception e ) {
125+ Logger .e (TAG , String .format ("Unexpected exception for request %s." , requestId ), e );
126+ error = new ErrorInfo (ErrorInfo .UNKNOWN_ERROR , e . getMessage () );
135127 requestResultStatus = FAILURE ;
128+ } finally {
129+ runningJobs .decrementAndGet ();
136130 }
137131 } else {
132+ Logger .d (TAG , String .format ("Failing request %s, payload cannot be loaded." , requestId ));
133+ error = new ErrorInfo (ErrorInfo .PAYLOAD_LOAD_FAILURE , "Request payload could not be loaded." );
138134 requestResultStatus = FAILURE ;
139- error = new ErrorInfo (ErrorInfo .PAYLOAD_EMPTY , "Request payload is empty." );
140- Logger .d (TAG , String .format ("Failing request %s, Uri is empty." , requestId ));
141135 }
142136 } else {
143137 requestResultStatus = FAILURE ;
144- error = new ErrorInfo (ErrorInfo .OPTIONS_FAILURE , "Options could not be loaded ." );
145- Logger .d (TAG , String .format ("Failing request %s, cannot load options ." , requestId ));
138+ error = new ErrorInfo (ErrorInfo .PAYLOAD_EMPTY , "Request payload is empty ." );
139+ Logger .d (TAG , String .format ("Failing request %s, Uri is empty ." , requestId ));
146140 }
147141 } else {
148- // safety - this should not really happen - the last error should already trigger
149- // as failure and should not be rescheduled
150- error = getMaxRetryError (errorCount );
151142 requestResultStatus = FAILURE ;
143+ error = new ErrorInfo (ErrorInfo .OPTIONS_FAILURE , "Options could not be loaded." );
144+ Logger .d (TAG , String .format ("Failing request %s, cannot load options." , requestId ));
152145 }
153146
154147 if (requestResultStatus .isFinal ()) {
0 commit comments