Skip to content

Commit

Permalink
Default error messages fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartmr committed Jun 19, 2022
1 parent 2354b83 commit 907e6f1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "not-me",
"version": "5.0.0",
"version": "5.1.0",
"description": "Easy and type-safe validation",
"main": "lib/index.js",
"types": "lib/types.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export type DefaultErrorMessages = Partial<{
moreThanMaximum: (maxLength: number) => string;
}>;
base: Partial<{
isNull: string;
isUndefined: string;
cannotBeNull: string;
cannotBeUndefined: string;
isRequired: string;
}>;
equals: Partial<{
notEqual: string;
Expand All @@ -27,7 +28,4 @@ export type DefaultErrorMessages = Partial<{
boolean: Partial<{
notABoolean: string;
}>;
null: Partial<{
notNull: string;
}>;
}>;
17 changes: 14 additions & 3 deletions src/schemas/base/base-schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DefaultErrorMessagesManager } from "../../error-messages/default-messages/default-error-messages-manager";
import { throwError } from "../../utils/throw-error";
import {
ValidationResult,
Expand Down Expand Up @@ -259,21 +260,31 @@ export abstract class BaseSchema<
protected markAsDefinedInternally(message: undefined | string): void {
this.otherFilters.push({
type: FilterType.UndefinedCatching,
message: message || "Input must be defined",
message:
message ||
DefaultErrorMessagesManager.getDefaultMessages().base
?.cannotBeUndefined ||
"Input must be defined",
});
}

protected markAsNotNullInternally(message: undefined | string): void {
this.otherFilters.push({
type: FilterType.NullCatchingFilter,
message: message || "Input cannot be null",
message:
message ||
DefaultErrorMessagesManager.getDefaultMessages().base?.cannotBeNull ||
"Input cannot be null",
});
}

protected markAsRequiredInternally(message: undefined | string): void {
this.otherFilters.push({
type: FilterType.NullableCatchingFilter,
message: message || "Input is required",
message:
message ||
DefaultErrorMessagesManager.getDefaultMessages().base?.isRequired ||
"Input is required",
});
}

Expand Down

0 comments on commit 907e6f1

Please sign in to comment.