Skip to content

Add error details to raised validation errors#14

Closed
vfonic wants to merge 2 commits intopenseo:masterfrom
vfonic:add-error-details
Closed

Add error details to raised validation errors#14
vfonic wants to merge 2 commits intopenseo:masterfrom
vfonic:add-error-details

Conversation

@vfonic
Copy link
Copy Markdown
Contributor

@vfonic vfonic commented Feb 1, 2021

WebFlow API sometimes provides the problems array field which sometimes adds more details about the returned error.
In my case, I was receiving "ValidationError" back, but I didn't know which field failed validation and why.

This PR adds the problems array to the raised error message so that the users of webflow-ruby can get more information into what caused the error.

https://developers.webflow.com/#errors

PS This was difficult to test. I ran the test by connecting to my WebFlow site and then manually changed the VCR cassette. Perhaps it would be best to re-record this after you add the validation on name to be on a single line.

Before

Webflow::Error: Validation Failure
/Users/viktor/.rvm/gems/ruby-2.6.6/gems/webflow-ruby-1.2.0/lib/webflow/client.rb:135:in `request'
/Users/viktor/.rvm/gems/ruby-2.6.6/gems/webflow-ruby-1.2.0/lib/webflow/client.rb:113:in `post'
/Users/viktor/.rvm/gems/ruby-2.6.6/gems/webflow-ruby-1.2.0/lib/webflow/client.rb:94:in `create_item'

After

Webflow::Error: Validation Failure
Field 'name': Expected value to be a single line: 'Monday:\r\n' +
  'Fever\r\n'
/Users/viktor/Developer/Ruby/webflow-ruby/lib/webflow/client.rb:135:in `request'
/Users/viktor/Developer/Ruby/webflow-ruby/lib/webflow/client.rb:113:in `post'
/Users/viktor/Developer/Ruby/webflow-ruby/lib/webflow/client.rb:94:in `create_item'

@phoet
Copy link
Copy Markdown
Contributor

phoet commented Feb 1, 2021

did you see that the tests include webflow api credentials that use a test-page? https://github.com/penseo/webflow-ruby/blob/master/test/webflow_test.rb#L3-L6

you can use that to regenerate whatever is necessary (aka batteries included)

@vfonic
Copy link
Copy Markdown
Contributor Author

vfonic commented Feb 1, 2021

@phoet yes, I can use that to access the API. However, WebFlow API doesn't allow you to create collections or fields in collections. I need a field that is set to be single line and then it fails validation with the validation message shown in problems field of returned JSON.

What I did was: I created such field in one of my sites and then ran the test, recorded that and changed couple of things like collection ID. I think perhaps the best way to make sure this is all well done, without any mistakes on my end, you could create a field and set it to be single line and then remove the VCR cassette recording and run the test to generate it yourself.

EDIT: I didn't do this test on name field. Now thinking of it, I don't think that name field type can be modified to have the validation of being a single line.

@phoet phoet closed this Feb 9, 2021
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.

2 participants