Skip to content

Commit

Permalink
remove redundant extraData from error
Browse files Browse the repository at this point in the history
also make method private
  • Loading branch information
mifi committed Jun 15, 2022
1 parent f80f437 commit 51b21a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions packages/@uppy/companion/src/server/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ class Uploader {
const ret = await this.uploadStream(stream)
if (!ret) return
const { url, extraData } = ret
this.emitSuccess(url, extraData)
this.#emitSuccess(url, extraData)
} catch (err) {
if (err instanceof AbortError) {
logger.error('Aborted upload', 'uploader.aborted', this.shortToken)
return
}
// console.log(err)
logger.error(err, 'uploader.error', this.shortToken)
this.emitError(err)
this.#emitError(err)
} finally {
emitter().removeAllListeners(`pause:${this.token}`)
emitter().removeAllListeners(`resume:${this.token}`)
Expand Down Expand Up @@ -460,7 +460,7 @@ class Uploader {
* @param {string} url
* @param {object} extraData
*/
emitSuccess (url, extraData) {
#emitSuccess (url, extraData) {
const emitData = {
action: 'success',
payload: { ...extraData, complete: true, url },
Expand All @@ -473,14 +473,12 @@ class Uploader {
*
* @param {Error} err
*/
emitError (err) {
#emitError (err) {
// delete stack to avoid sending server info to client
// todo remove also extraData from serializedErr in next major
const { stack, ...serializedErr } = serializeError(err)
const { stack, ...payload } = serializeError(err)
const dataToEmit = {
action: 'error',
// @ts-ignore
payload: { ...err.extraData, error: serializedErr },
payload,
}
this.saveState(dataToEmit)
emitter().emit(this.token, dataToEmit)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/test/__tests__/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('uploader with tus protocol', () => {
return new Promise((resolve, reject) => {
socketClient.onUploadError(uploadToken, (message) => {
try {
expect(message).toMatchObject({ payload: { error: { message: 'maxFileSize exceeded' } } })
expect(message).toMatchObject({ payload: { message: 'maxFileSize exceeded' } })
resolve()
} catch (err) {
reject(err)
Expand Down

0 comments on commit 51b21a9

Please sign in to comment.