Module: ActAsJsonapi::JSONErrors

Extended by:
ActiveSupport::Concern
Included in:
Controller
Defined in:
lib/act_as_jsonapi/json_errors.rb

Instance Method Summary collapse

Instance Method Details

#render_bad_requestObject



28
29
30
# File 'lib/act_as_jsonapi/json_errors.rb', line 28

def render_bad_request
  render_error :bad_request
end

#render_conflict_requestObject



52
53
54
# File 'lib/act_as_jsonapi/json_errors.rb', line 52

def render_conflict_request
  render_error :conflict
end

#render_error(error_status, detail_code = nil, detail_meta = nil) ⇒ Object



18
19
20
21
22
# File 'lib/act_as_jsonapi/json_errors.rb', line 18

def render_error(error_status, detail_code = nil, detail_meta = nil )
  detail = translate_detail_code(detail_code)
  serializer = ::RequestErrorSerializer.new serializable(error_status, detail , detail_meta)
  render_json_api serializer, status: error_status
end

#render_failed_dependencyObject



40
41
42
# File 'lib/act_as_jsonapi/json_errors.rb', line 40

def render_failed_dependency
  render_error :failed_dependency
end

#render_forbidden(ex) ⇒ Object



36
37
38
# File 'lib/act_as_jsonapi/json_errors.rb', line 36

def render_forbidden(ex)
  render_error :forbidden, :err_forbidden, ex.message
end

#render_not_authorizedObject



32
33
34
# File 'lib/act_as_jsonapi/json_errors.rb', line 32

def render_not_authorized
  render_error :unauthorized
end

#render_not_foundObject



24
25
26
# File 'lib/act_as_jsonapi/json_errors.rb', line 24

def render_not_found
  render_error :not_found
end

#render_service_unavailableObject



48
49
50
# File 'lib/act_as_jsonapi/json_errors.rb', line 48

def render_service_unavailable
  render_error :service_unavailable
end

#render_unprocessable_entityObject



44
45
46
# File 'lib/act_as_jsonapi/json_errors.rb', line 44

def render_unprocessable_entity
  render_error :unprocessable_entity
end

#serializable(error_status, detail, detail_meta) ⇒ Object



8
9
10
# File 'lib/act_as_jsonapi/json_errors.rb', line 8

def serializable(error_status, detail, detail_meta)
  StatusCodeResponse.serializable(error_status, detail, detail_meta)
end

#translate_detail_code(detail_code) ⇒ Object



12
13
14
15
16
# File 'lib/act_as_jsonapi/json_errors.rb', line 12

def translate_detail_code(detail_code)
  detail = I18n.t("error_messages.#{detail_code.to_s}")
  return detail unless detail.include?("translation missing")
  detail = I18n.t("error_messages.err_standard")
end