Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add new InputNameConflictError #78

Merged
merged 2 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}