voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.52k stars 241 forks source link

validator.rb custom_open throws uncaught SocketError #422

Open ntli239 opened 5 years ago

ntli239 commented 5 years ago

When trying to validate a string that looks like URI, but is not a real one, the error thrown in custom_open is SocketError, not OpenURI::HTTPError, Timeout::Error. It is not caught here, but by other more generic app layer, and is not processed properly as a result. When SocketError is added to the rescue list as a patch, everything works as expected. Could you please update the main code?

RST-J commented 5 years ago

Could you please provide a failing test case which should pass with the suggested fix?

ntli239 commented 5 years ago

Hi RST-J Sorry about the delay

 data = "http://google.com"
 schema = {
        "type": "String",
         "maxLength": 100
 }
errors = JSON::Validator.fully_validate(schema,data)
assert(errors.empty?)

There is one difference I found though, when running this from CLT: the error thrown is WebMock::NetConnectNotAllowedError, not SocketError I had inside the app.

Thank you!