-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a comment
errors/InputValidationError.js
Outdated
// Import base error | ||
const { BaseIsomerError } = require('./BaseError') | ||
|
||
class InputNameConflictError extends BaseIsomerError { |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved with 10ab103
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* Feat: add new InputNameConflictError * Fix: switch to error identification using HTTP error code
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.