Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine du Hamel <antoine@transloadit.com>
  • Loading branch information
mifi and aduh95 authored Dec 5, 2023
1 parent 5025a73 commit 761dcdc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
7 changes: 2 additions & 5 deletions packages/@uppy/companion/src/server/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ function sanitizeMetadata(inputMetadata) {
}

class AbortError extends Error {
constructor(message) {
super(message)
this.isAbortError = true
}
isAbortError = true
}

class ValidationError extends Error {
Expand Down Expand Up @@ -317,7 +314,7 @@ class Uploader {
const { url, extraData } = ret
this.#emitSuccess(url, extraData)
} catch (err) {
if (err.isAbortError) {
if (err?.isAbortError) {
logger.error('Aborted upload', 'uploader.aborted', this.shortToken)
return
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/companion/src/server/provider/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class ProviderAuthError extends ProviderApiError {
*/
function errorToResponse(err) {
// @ts-ignore
if (err.isAuthError) {
if (err?.isAuthError) {
return { code: 401, json: { message: err.message } }
}

if (err.name === 'ProviderUserError') {
if (err?.name === 'ProviderUserError') {
// @ts-ignore
return { code: 400, json: err.json }
}

if (err.name === 'ProviderApiError') {
if (err?.name === 'ProviderApiError') {
// @ts-ignore
if (err.statusCode >= 500) {
// bad gateway i.e the provider APIs gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ async function withProviderErrorHandling({
let statusCode
let body

if (err.name === 'HTTPError') {
if (err?.name === 'HTTPError') {
statusCode = err.response?.statusCode
body = err.response?.body
} else if (err.name === 'StreamHttpJsonError') {
} else if (err?.name === 'StreamHttpJsonError') {
statusCode = err.statusCode
body = err.responseJson
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default class ProviderView extends View {
} catch (err) {
// This is the first call that happens when the provider view loads, after auth, so it's probably nice to show any
// error occurring here to the user.
if (err.name === 'UserFacingApiError') {
if (err?.name === 'UserFacingApiError') {
this.plugin.uppy.info({ message: this.plugin.uppy.i18n(err.message) }, 'warning', 5000)
return
}
Expand Down
5 changes: 1 addition & 4 deletions packages/@uppy/utils/src/UserFacingApiError.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class UserFacingApiError extends Error {
constructor (message) {
super(message)
this.name = 'UserFacingApiError'
}
name = 'UserFacingApiError'
}

export default UserFacingApiError

0 comments on commit 761dcdc

Please sign in to comment.