Messages Definitions - thisisqubika/angus GitHub Wiki

What are messages for?

They are for exception handling. Each message provides the info Angus needs to properly respond to an exception raised by your ruby code.

When do I need a message?

Let's say you were trying to get a post by it's id. But the post wasn't found. So what you should do is respond with 404 - not found. The way to do this in Angus is to raise a custom exception let's name it PostNotFoundError, which you should define as a class inheriting from StandardError.

class PostNotFoundError < StandardError
  def message
    "Post not found."
  end
end

Now we need to add an entry in messages.yml so angus knows how to handle this exception:

PostNotFoundError:
  status_code: 404
  level: error
  description: No Post found for the given id.

This will tell angus to return a 404 and the message given by the error's message method. So every time you throw an exception in your code remember to add the message definition in the messages.yml.