File tree Expand file tree Collapse file tree 6 files changed +34
-8
lines changed
micro-services/emails-fetcher/src Expand file tree Collapse file tree 6 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -451,7 +451,6 @@ export default function initializeMiningController(
451451 data : fileMiningTask
452452 } ) ;
453453 } catch ( err ) {
454- res . status ( 500 ) ;
455454 return next ( err ) ;
456455 }
457456 } ,
@@ -514,7 +513,13 @@ export default function initializeMiningController(
514513 return res . sendStatus ( 409 ) ;
515514 }
516515
517- res . status ( 500 ) ;
516+ if (
517+ err instanceof Error &&
518+ err . message === 'Failed to parse PST file'
519+ ) {
520+ return res . status ( 422 ) . json ( { message : err . message } ) ;
521+ }
522+
518523 return next ( err ) ;
519524 }
520525 } ,
Original file line number Diff line number Diff line change @@ -44,6 +44,15 @@ class PSTFetcherClient {
4444 error,
4545 payload
4646 } ) ;
47+ if (
48+ axios . isAxiosError ( error ) &&
49+ error . response &&
50+ error . response . status === 422 &&
51+ error . response . data . message === 'Failed to parse PST file'
52+ ) {
53+ throw new Error ( error . response . data . message ) ;
54+ }
55+
4756 throw error ;
4857 }
4958 }
Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ export default class TasksManagerPST {
267267 logger . error ( `Failed to start fetching task with id: ${ miningId } ` , {
268268 error
269269 } ) ;
270- throw new Error ( 'Failed to start fetching' ) ;
270+ throw error ;
271271 }
272272
273273 this . redisSubscriber . subscribe ( miningId , ( err ) => {
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ const ERROR_STATUS_MESSAGES: ErrorStatusMessages = {
1717 400 : 'Oops! Something went wrong. Please double-check your input and try again.' ,
1818 401 : "Sorry, you're not authorized. Please log in and try again." ,
1919 403 : 'Access denied. Please contact support if you need assistance.' ,
20- 404 : "what you're looking for couldn't be found." ,
20+ 404 : "What you're looking for couldn't be found." ,
21+ 422 : "We couldn't process this file, Please try another one." ,
2122 500 : 'Something went wrong on our end. Please try again later.' ,
2223 502 : 'Our server is having issues. Please try again later.' ,
2324 503 : 'Service is temporarily unavailable. Please check your connection or try again later.' ,
@@ -53,6 +54,9 @@ function networkErrorMessage(err: unknown) {
5354
5455function otherErrorMessages ( err : unknown ) {
5556 if ( isFetchError ( err ) && err . response ) {
57+ if ( err . response . status === 422 ) {
58+ return ERROR_STATUS_MESSAGES [ err . response . status ] ;
59+ }
5660 return (
5761 err . response . _data . message ?? ERROR_STATUS_MESSAGES [ err . response . status ]
5862 ) ;
Original file line number Diff line number Diff line change @@ -338,6 +338,12 @@ apiRoutes.post(
338338 } ) ;
339339 } catch ( err ) {
340340 logger . error ( 'Failed to start fetching' , err ) ;
341+ if (
342+ err instanceof Error &&
343+ err . stack ?. includes ( 'Failed to parse PST file' )
344+ ) {
345+ return res . status ( 422 ) . json ( { message : 'Failed to parse PST file' } ) ;
346+ }
341347 if (
342348 err instanceof Error &&
343349 err . message . toLowerCase ( ) . startsWith ( 'invalid credentials' )
@@ -352,10 +358,8 @@ apiRoutes.post(
352358 return res . sendStatus ( 409 ) ;
353359 }
354360
355- const newError = generateErrorObjectFromImapError ( err ) ;
356-
357361 res . status ( 500 ) ;
358- return next ( new Error ( newError . message ) ) ;
362+ return next ( err ) ;
359363 }
360364 }
361365) ;
Original file line number Diff line number Diff line change @@ -450,7 +450,11 @@ export default class PSTEmailsFetcher {
450450
451451 const writeStream = fs . createWriteStream ( this . localPstFilePath ) ;
452452 await pipeline ( res . body , writeStream ) ;
453- this . pstFile = new PSTFile ( this . localPstFilePath ) ;
453+ try {
454+ this . pstFile = new PSTFile ( this . localPstFilePath ) ;
455+ } catch ( err ) {
456+ throw new Error ( 'Failed to parse PST file' , { cause : err } ) ;
457+ }
454458 }
455459
456460 /**
You can’t perform that action at this time.
0 commit comments