Skip to content

Commit

Permalink
Feat: add new InputNameConflictError (#78)
Browse files Browse the repository at this point in the history
* Feat: add new InputNameConflictError

* Fix: switch to error identification using HTTP error code
  • Loading branch information
alexanderleegs authored Nov 24, 2020
1 parent 81e89c5 commit c553da4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions classes/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const _ = require('lodash')
const validateStatus = require('../utils/axios-utils')

// Import error
const { NotFoundError } = require('../errors/NotFoundError')
const { NotFoundError } = require('../errors/NotFoundError')
const { ConflictError, inputNameConflictErrorMsg } = require('../errors/ConflictError')

const GITHUB_ORG_NAME = process.env.GITHUB_ORG_NAME
const BRANCH_REF = process.env.BRANCH_REF
Expand Down Expand Up @@ -78,7 +79,9 @@ class File {

return { sha: resp.data.content.sha }
} catch (err) {
throw err
const status = err.response.status
if (status === 422) throw new ConflictError(inputNameConflictErrorMsg(fileName))
throw err.response
}
}

Expand Down
17 changes: 17 additions & 0 deletions errors/ConflictError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Import base error
const { BaseIsomerError } = require('./BaseError')

const inputNameConflictErrorMsg = (fileName) => `A file with ${fileName} already exists.`

class ConflictError extends BaseIsomerError {
constructor (fileName) {
super(
409,
`A file with ${fileName} already exists.`
)
}
}
module.exports = {
ConflictError,
inputNameConflictErrorMsg,
}

0 comments on commit c553da4

Please sign in to comment.