graphiti-api / graphiti-rails

MIT License
54 stars 28 forks source link

More exception handling options #8

Closed wagenet closed 5 years ago

wagenet commented 5 years ago

https://github.com/wagenet/graphiti-rails/blob/eeb6b6d91e2739a7d324205bba6975b52a668109/lib/graphiti/rails.rb#L54-L56

Right now when debugging exceptions we only use the default handler. That means there's no equivalent of GraphitiErrors.register_exception where a different handler can be specified. We also don't support the new InvalidRequest error.

wagenet commented 5 years ago

See also https://github.com/wagenet/graphiti-rails/issues/5#issuecomment-488733910

richmolj commented 5 years ago

Since we have access to the error, I wonder if the ExceptionHandler interface would best look like

def initialize(error, options)
  @error, @options = error, options
end

def status
  @options[:status] || 500
end

# etc

Then in AD we could

config = get_config_from_registry
handler = Graphiti::Rails::ExceptionHandler.new(e, config)
handler.status
handler.to_jsonapi # to_json, to_xml etc

# meaning we would do something like
render(handler.status, handler, content_type)
wagenet commented 5 years ago

For the first pass, I've decided to use the default handler and the InvalidRequest handlers only. I'm not initially encouraging people to register their own handlers, again this is because we may not even hit the GraphitiError handlers.