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

fix: Validation error of user request returns HTTP 500 #263

Merged
merged 1 commit into from
Apr 26, 2020

Conversation

sandrask
Copy link
Contributor

Fixed resolution and resolution with initial state to return bad request in case that user supplies invalid input

Operation processing has been fixed with issue #201 (operation validation on server side)

Closes #149

Signed-off-by: Sandra Vrtikapa [email protected]

@cla-bot cla-bot bot added the cla-signed label Apr 26, 2020
@codecov
Copy link

codecov bot commented Apr 26, 2020

Codecov Report

Merging #263 into master will increase coverage by 0.00%.
The diff coverage is 92.30%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #263   +/-   ##
=======================================
  Coverage   91.87%   91.87%           
=======================================
  Files          50       50           
  Lines        2510     2512    +2     
=======================================
+ Hits         2306     2308    +2     
- Misses        110      111    +1     
+ Partials       94       93    -1     
Impacted Files Coverage Δ
pkg/dochandler/handler.go 86.36% <88.88%> (+1.81%) ⬆️
pkg/dochandler/didvalidator/validator.go 98.09% <100.00%> (ø)
pkg/internal/request/method.go 100.00% <100.00%> (ø)
pkg/restapi/dochandler/resolvehandler.go 94.11% <100.00%> (+0.36%) ⬆️
pkg/batch/writer.go 91.50% <0.00%> (-1.31%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60ca63d...562bc8d. Read the comment docs.

@@ -60,6 +60,9 @@ func (o *ResolveHandler) doResolve(id string) (*document.ResolutionResult, error

doc, err := o.resolver.ResolveDocument(id)
if err != nil {
if strings.Contains(err.Error(), "bad request") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we instead define a 'BadRequest' error and then use errors.Is(...) to determine that it's the cause? I find that matching a string within the error is not reliable. I was already thinking about refactoring the code that searches for "not found".

Copy link
Contributor Author

@sandrask sandrask Apr 26, 2020

Choose a reason for hiding this comment

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

Should I provide details about error? We usually use this pattern if error is constant e.g.
var ErrNotFound = errors.New("did not found under given key")

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that a new 'BadRequestError' type should be defined which has a code. The code contains a specific value that's defined in an enumeration. This is what's done for the cas REST endpoint: https://github.com/trustbloc/sidetree-fabric/blob/master/pkg/rest/dcashandler/retrieveerror.go

Copy link
Contributor Author

@sandrask sandrask Apr 26, 2020

Choose a reason for hiding this comment

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

You have 5 status codes there. If I would capture all validations it would probably be more than 30 status codes plus they are all over the place because of the nature of resolution with initial state (parse did, parse initial state parameter, validate initial document, parse operation which involves suffix, delta patches (keys, services), reveal values, commitment values, hashes, recovery key etc). I can create new issue for that and we can address it later on.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, this can be done later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #264

Fixed resolution and resolution with initial state to return bad request in case that user supplies invalid input

Operation processing has been fixed with issue trustbloc#201 (operation validation on server side)

Closes trustbloc#149

Signed-off-by: Sandra Vrtikapa <[email protected]>
@sandrask sandrask merged commit eb5e95c into trustbloc:master Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation error of user request returns HTTP 500
3 participants