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

kotlinx.serialization error message exposed in /wallet-api/auth/login #72

Open
alegomes opened this issue Jan 19, 2024 · 3 comments
Open
Labels

Comments

@alegomes
Copy link
Contributor

Version tested: v1.0.2401181053-SNAPSHOT

If the type field is omitted or misspelled, the returning error message is an internal kotlinx.serialization exception.

Wouldn't it be better to encapsulate it in a more readable, domain-specific message, as is the case with the handling of the email and password fields?

Error handling of type field with a difficult-to-debug message

Request

curl -X 'POST' \
  'http://localhost:4545/wallet-api/auth/login' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "user@email.com",
  "password": "password",
  "type": "email_"
}

Response

{"exception":"true","status":"Bad Request","code":"400","message":"Polymorphic serializer was not found for class discriminator 'email_'\nJSON input: {\"email\":\"user@email.com\",\"password\":\"password\",\"type\":\"email_\"}"}

Error handling of the email field, although imperfect, is more readable than the previous case

Request

curl -X 'POST' \
  'http://localhost:4545/wallet-api/auth/login' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "_email": "user@email.com",
  "password": "password",
  "type": "email"
}'

Response

{"exception":"true","status":"Bad Request","code":"400","message":"Field 'email' is required for type with serial name 'email', but it was missing at path: $"}
Copy link

This issue has been marked as stale.

@alegomes
Copy link
Contributor Author

The github bot marked this issue as "stale", but I keep my point.

I'm afraid this kind of error should be treated before being thrown to the end user.

"Serializer for subclass 'email_' is not found in the polymorphic scope of 'AccountRequest'.\nCheck if class with serial name 'email_' exists and serializer is registered in a corresponding SerializersModule.\nTo be registered automatically, class 'email_' has to be '@Serializable', and the base class 'AccountRequest' has to be sealed and '@Serializable'.\nJSON input: {\"email\":\"user@email.com\",\"password\":\"password\",\"type\":\"email_\"}"

It's and internal kotlinx.serialization error message that is not supposed to make any sense to the SSI user.

My suggestion is to treat it the same way other fields validations are made, like this:

image

It's also related to this other issue:

#71

Copy link

This issue has been marked as stale.

@github-actions github-actions bot added the Stale label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant