development REST API service

hello, i develop rest api for my project and using grape And i have two questions:

  1. For every error i want to have some specific code. Like twillio. where should I store these codes?
  2. How should I organize the work with the codes and grape? For example: I have user model class User < ActiveRecord::Base validates :phone, presence: true # code 1001 validated :phone, uniqueness: true # code 1002 validates :first_name, presence: true # code 1003 validates :last_name, presence: true #code 1004 end In grape api i have something like this post do authenticated! user = User.new(params) if user.save { id: user.id } else error!({ errors: user.errors }, 422) end end I thought to use the function fail and using Grape rescue_from generate response but I’m not sure that this is true