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

Conversation

alexanderleegs
Copy link
Contributor

@alexanderleegs alexanderleegs commented Nov 23, 2020

This PR introduces a new error for handling the case where we fail to create a new file due to conflicting file names. This PR is to be reviewed in conjunction with PR #247 on the isomercms-frontend repo.

One thing to note is that we convert the error thrown by the Github API when processing - this is due to the endpoint that we are calling to create a new file also being used to modify existing files, thus the Github API returns us a 422 Unprocessable Entity error due to the missing sha, when we actually want to reflect that there is a conflict in file names.

Copy link
Contributor

@kwajiehao kwajiehao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a comment

// Import base error
const { BaseIsomerError } = require('./BaseError')

class InputNameConflictError extends BaseIsomerError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the isomerCMS project, we've been trying to switch to a different custom error system where the error is solely identified by the HTTP error code, to avoid a situation where we have way too many custom errors as we did in Homer. In keeping with this new strategy, this should be a ConflictError with an argument in the constructor for the error message.

To standardize the error messages, we can define the types of ConflictError messages and export them. For example, we can have:

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

class ConflictError extends BaseIsomerError { ... }

module.exports = {
  inputNameConflictErrorMsg,
  ConflictError,
}

and then throw the error like this:

throw new ConflictError(inputNameConflictErrorMsg(fileName))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved with 10ab103

Copy link
Contributor

@kwajiehao kwajiehao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@alexanderleegs alexanderleegs merged commit c553da4 into staging Nov 24, 2020
@alexanderleegs alexanderleegs deleted the feat/file-name-conflict-handling branch November 24, 2020 07:24
@kwajiehao kwajiehao mentioned this pull request Dec 9, 2020
harishv7 pushed a commit that referenced this pull request Feb 17, 2023
* Feat: add new InputNameConflictError

* Fix: switch to error identification using HTTP error code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants