Skip to content

Commit

Permalink
Merge 4046430 into 65b6913
Browse files Browse the repository at this point in the history
  • Loading branch information
victorperin committed Oct 16, 2022
2 parents 65b6913 + 4046430 commit 739d5e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/handlers/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ describe('error handler', () => {

expect(functionToTest).toThrowError('[ERROR] File <SOME PATH> not found!')
})

it('should throw error if input is a string', () => {
// Arrange
const input = 'a generic error'

// Act
const functionToTest = () => scanFromFile('SOME PATH')(input)

// Assert
expect(functionToTest).toThrowError('a generic error')
})
})

describe('scanFromBitmap', () => {
Expand All @@ -43,5 +54,16 @@ describe('error handler', () => {

expect(functionToTest).toThrowError('[WARNING]')
})

it('should thow error from input', () => {
// Arrange
const input = new Error('a generic error')

// Act
const functionToTest = () => scanFromBitmap(input)

// Assert
expect(functionToTest).toThrowError(input)
})
})
})
8 changes: 5 additions & 3 deletions src/handlers/error.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
export const scanFromFile =
(filePath: string) =>
(error: Error): never => {
if (error.message.includes('no such file or directory'))
(error: Error | string): never => {
if (typeof error === 'string') throw new Error(error)

if (error?.message?.includes('no such file or directory'))
throw new Error(`[ERROR] File <${filePath}> not found!`)

throw error
}

export const scanFromBitmap = (error: Error | string): never => {
if (typeof error === 'string' && error.includes('0 patterns found'))
if (typeof error === 'string' && error?.includes('0 patterns found'))
throw new Error('[WARNING] No pattern could be found! Is there a QR-Code?')

throw error
Expand Down

0 comments on commit 739d5e4

Please sign in to comment.