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

1.0.0 #1

Merged
merged 7 commits into from
Dec 16, 2019
Merged

1.0.0 #1

merged 7 commits into from
Dec 16, 2019

Conversation

bilgeyucel
Copy link
Contributor

  • Add generateSpesificFieldError and generateErrorMessage functions

@@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mapUtils_1 = require("./utils/mapUtils");
const errorConstants_1 = require("./utils/errorConstants");

Choose a reason for hiding this comment

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

Why do we need to add a number suffix?

Choose a reason for hiding this comment

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

This is the output file. You can just review the ts files

lib/ExceptionTransformer.js Outdated Show resolved Hide resolved
lib/ExceptionTransformer.js Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
) {
if (typeof errorDetail.non_field_errors[0] === "string") {
message = errorDetail.non_field_errors[0];
} else {

Choose a reason for hiding this comment

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

I will open an issue about this to extract a logical error message from errorDetail.non_field_errors[0] if it exists. So in your first if block, the condition should just check if errorDetail.non_field_errors[0] is null or undefined and then we will recursively look for a value. We can publish without making this enhancement but it will be a good addition.


if (unknownErrorKeys.length) {
message = `${unknownErrorKeys[0]}: ${
errorDetail[unknownErrorKeys[0]]

Choose a reason for hiding this comment

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

That same recursive function should be used here that extract a message from unknownErrorKeys[0] because it may not be a simple string. The function would take unknownErrorKeys[0] as argument and check and extract the first logical error message.

src/utils/errorConstants.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
@edizcelik
Copy link

Please upgrade the dependency versions to the latest here as well

* Pass `genericErrorMessage` to class object as a parameter
* Add `getErrorDetail` util function
* Update `compilerOptions`
* Update version to `1.0.0`
@bilgeyucel
Copy link
Contributor Author

Thanks for the review. Changes are made @edizcelik @bedirhankaradogan

Copy link
Contributor

@mucahit mucahit left a comment

Choose a reason for hiding this comment

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

Thanks! @bilgeyucel

src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/utils/errorUtils.ts Outdated Show resolved Hide resolved
src/utils/errorUtils.ts Outdated Show resolved Hide resolved
* A long string created with nested key names can be provided as `fieldName` to `getFieldError` function.
* errorDetail can be `string[]`, `ExceptionDetail` or `ExceptionDetail[]`. Consider this in `generateErrorMessage` function
* `genericErrorMessage` is required to initialize `ExceptionTransformer`. `onExceptonExceptioio` is optional.
* Add new util functions to `errorUtils`
* Make more strict type checkings
* Add explanatory informations as comment

Related issue: #2
@bilgeyucel bilgeyucel requested a review from mucahit November 26, 2019 15:28
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/utils/errorUtils.ts Outdated Show resolved Hide resolved
src/utils/errorUtils.ts Outdated Show resolved Hide resolved
src/utils/errorUtils.ts Outdated Show resolved Hide resolved
src/utils/errorUtils.ts Outdated Show resolved Hide resolved
src/utils/errorUtils.ts Outdated Show resolved Hide resolved
…r` returns string[] or undefined

* Improve `deleteProperty` and `getValueFromPath` functions by giving them type
* Change `ExceptionDetail` type
* Make sure `generateSpecificFieldError` returns string[] or undefined
* Change some namings
@bilgeyucel
Copy link
Contributor Author

Thanks for the review @edizcelik , changes are made.

@bilgeyucel bilgeyucel requested a review from edizcelik November 29, 2019 13:43
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
}
this.genericErrorMessage = genericErrorMessage;

Choose a reason for hiding this comment

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

I think it would be useful for some certain cases, such as changing language of an app, that I am able to modify genericErrorMessage after initialization

Copy link
Contributor Author

@bilgeyucel bilgeyucel Dec 16, 2019

Choose a reason for hiding this comment

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

Added a new function: changeGenericErrorMessage to change genericErrorMessage

src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
shouldDisplayFallbackMessage = true;
}

if (shouldDisplayFallbackMessage) {

Choose a reason for hiding this comment

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

Instead of having a variable for this, would it work to just check against message ?

Suggested change
if (shouldDisplayFallbackMessage) {
if (!message) {

It seems this would work because it means that we couldn't generate a message from the provided errorDetail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not possible to change the check like this since when all the errors are known, message will be "" again. This would create confusion.
But we can change if (shouldDisplayFallbackMessage) to else since now there is no other possibility.

src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
src/ExceptionTransformer.ts Outdated Show resolved Hide resolved
* Add `removeKnownKeysFromErrorDetail` and `generateFieldErrorFromErrorDetail`
* Add `changeGenericErrorMessage` to change generic error message after initializing `exceptionTransformer`
* Make necessary changes for npm upload
@bilgeyucel bilgeyucel requested a review from brkn December 16, 2019 10:15
@bilgeyucel bilgeyucel merged commit 3dd53e9 into master Dec 16, 2019
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.

5 participants