Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Nov 27, 2023
1 parent 8794f63 commit 42f74b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions packages/@uppy/companion/src/server/provider/providerErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ const { StreamHttpJsonError } = require('../helpers/utils')
/**
*
* @param {{
* fn: () => any, tag: string, providerName: string, isAuthError?: (a: { statusCode: number, body?: object }) => boolean, isUserFacingError?: (a: { statusCode: number, body?: object }) => boolean,
* fn: () => any,
* tag: string,
* providerName: string,
* isAuthError?: (a: { statusCode: number, body?: object }) => boolean,
* isUserFacingError?: (a: { statusCode: number, body?: object }) => boolean,
* getJsonErrorMessage: (a: object) => string
* }} param0
* @returns
*/
async function withProviderErrorHandling ({ fn, tag, providerName, isAuthError = () => false, isUserFacingError = () => false, getJsonErrorMessage }) {
async function withProviderErrorHandling ({
fn,
tag,
providerName,
isAuthError = () => false,
isUserFacingError = () => false,
getJsonErrorMessage,
}) {
function getErrorMessage ({ statusCode, body }) {
if (typeof body === 'object') {
const message = getJsonErrorMessage(body)
Expand Down Expand Up @@ -42,9 +53,13 @@ async function withProviderErrorHandling ({ fn, tag, providerName, isAuthError =

if (statusCode != null) {
let knownErr
if (isAuthError({ statusCode, body })) knownErr = new ProviderAuthError()
else if (isUserFacingError({ statusCode, body })) knownErr = new ProviderUserError({ message: getErrorMessage({ statusCode, body }) })
else knownErr = new ProviderApiError(getErrorMessage({ statusCode, body }), statusCode)
if (isAuthError({ statusCode, body })) {
knownErr = new ProviderAuthError()
} else if (isUserFacingError({ statusCode, body })) {
knownErr = new ProviderUserError({ message: getErrorMessage({ statusCode, body }) })
} else {
knownErr = new ProviderApiError(getErrorMessage({ statusCode, body }), statusCode)
}

logger.error(knownErr, tag)
throw knownErr
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/utils/src/dataURItoBlob.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import dataURItoBlob from './dataURItoBlob.ts'
import sampleImageDataURI from './sampleImageDataURI.js'
import sampleImageDataURI from './sampleImageDataURI.ts'

describe('dataURItoBlob', () => {
it('should convert a data uri to a blob', () => {
Expand Down

0 comments on commit 42f74b2

Please sign in to comment.