-
Notifications
You must be signed in to change notification settings - Fork 41
patch: file upload errors #1351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
741d35c
d8b14d4
1535832
62759cd
2763306
f2df74e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,16 +44,13 @@ export async function handleUpload( | |
} | ||
|
||
let response; | ||
|
||
const errors = new Set(); | ||
try { | ||
response = await uploadService.uploadDocuments(streams); | ||
} catch (err) { | ||
if (err.data?.res) { | ||
const { error } = uploadService.parsedDocumentUploadResponse(err.data); | ||
request.pre.errors = [ | ||
...request.pre.errors, | ||
parsedError(fieldName, error), | ||
]; | ||
response = uploadService.parsedDocumentUploadResponse(err.data); | ||
errors.add(response.error); | ||
} else if (err.code === "EPIPE") { | ||
// ignore this error, it happens when the request is responded to by the doc upload service before the | ||
// body has finished being sent. A valid response is still received. | ||
|
@@ -63,10 +60,7 @@ export async function handleUpload( | |
{ ...loggerIdentifier, err }, | ||
`Error uploading document: ${err.message}` | ||
); | ||
request.pre.errors = [ | ||
...(h.request.pre.errors || []), | ||
parsedError(fieldName, err), | ||
]; | ||
errors.add(err); | ||
} | ||
} | ||
|
||
|
@@ -108,9 +102,13 @@ export async function handleUpload( | |
loggerIdentifier, | ||
`Document upload API responded with an error ${error}` | ||
); | ||
errors.add(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be omitted, since it's handled in l51-53. I think that should remove the need for the set as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you have an error which doesn't go into the catch block, then it will not be added to the errors list (which is how the file upload tests work) so it needs to be added here |
||
} | ||
|
||
if(errors){ | ||
request.pre.errors = [ | ||
...(request.pre.errors || []), | ||
parsedError(fieldName, error), | ||
...Array.from(errors).map(e => parsedError(fieldName, String(e))) | ||
]; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep since we don't want to lose any errors that have accumulated up to this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenbutongit Is it safe to delete error writing in the if (error) on line 102 instead?
And is keeping "response = uploadService.parsedDocumentUploadResponse(err.data);" okay? I've done this so "const { location, warning, error } = response;" can unpack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it in this way will result in the error being added to request.pre.errors twice (when an error is thrown) - you add response.error in the catch, then unpack the response and add it again in the if(error) block. Do you need the response when an error is thrown? (e.g. are you using
location
orwarning
?)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@superafroman Do you want to resolve/review since the implementation has changed? My initial comment is also redundant.
As a side note - I've noticed an issue with the code (not introduced by this change).
uploadService.parsedDocumentUploadResponse
is called internally in uploadService, but is called again on err.data. We havehttpService.request
(andhttpService.post
) which looks like it wants to suppress the thrown error and return it in an object insteadLooking at
uploadService.uploadDocuments
- I think the intention is that it returns an object containing{ location, error, warning }
if there was a document upload API error but is never called since post request throws.I'm fine to resolve this in another PR/issue though.