Giter Site home page Giter Site logo

Comments (6)

mathieujobin avatar mathieujobin commented on June 1, 2024

I am thinking this might have happened due to a refactor. probably best to update the documentation, unless we're really missing out on something...

from apipie-rails.

davidwessman avatar davidwessman commented on June 1, 2024

Might be related to my change with returning multiple errors, so either we need to reconsider that change or update the documentation.

#886

from apipie-rails.

mathieujobin avatar mathieujobin commented on June 1, 2024

@davidwessman Can you update the documentation ?

from apipie-rails.

davidwessman avatar davidwessman commented on June 1, 2024

EDIT Now I realized the point about the different interfaces of param for ParamMissing vs ParamInvalid.
So my answer was probably not on point - sorry.

Previous answer @mathieujobin I reviewed the README and find that it has been updated to this syntax: ```ruby # ParamError is superclass of ParamMissing, ParamInvalid rescue_from Apipie::ParamError do |e| render text: e.message, status: :unprocessable_entity end ```

using e.message instead of e.param.


@wozza35 Where did you find the e.param example?


This is my suggestion to handle all the errors, but I am not sure if it should be in the README or not.

rescue_from Apipie::ParamError do |e|
  errors = if e.is_a?(Apipie::ParamMultipleMissing)
    e.params.to_h {|p| [p.name, "has an error"]}
  else
    {e.param => "has an error"}
  end
  
  render json: errors, status: :unprocessable_entity
end

from apipie-rails.

davidwessman avatar davidwessman commented on June 1, 2024

So it seems like these errors have always used different interfaces for the params.

ParamInvalid is initialized like:

def error
ParamInvalid.new(param_name, @error_value, description)
end

ParamMissing is initialized like:

def self.raise_if_missing_params
missing_params = []
yield missing_params
if missing_params.size > 1
raise ParamMultipleMissing.new(missing_params)
elsif missing_params.size == 1
raise ParamMissing.new(missing_params.first)
end
end

BaseValidator.raise_if_missing_params do |missing|
@hash_params&.each do |k, p|
if Apipie.configuration.validate_presence?
missing << p if p.required && !value.key?(k)
end
if Apipie.configuration.validate_value?
p.validate(value[k]) if value.key?(k)
end
end
end

So it seems like it would make sense the change the ParamInvalid error to receive the whole ParamDescription as well.
But that seems like breaking change :/

from apipie-rails.

mathieujobin avatar mathieujobin commented on June 1, 2024

Inconsistent interface isn't ideal, I convey, but considering the little audience of this gem. I'm not sure its worth fixing.

I guess if enough people vote that its worth it. otherwise, I think this is really minor. or at least, I don't see what exact problem is causes.

from apipie-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.