{"id":17929581,"url":"https://github.com/intrip/jsonapi_errors","last_synced_at":"2025-04-03T10:15:52.344Z","repository":{"id":56879488,"uuid":"48766548","full_name":"intrip/jsonapi_errors","owner":"intrip","description":"Framework Agnostic gem to handle JSON API errors","archived":false,"fork":false,"pushed_at":"2016-03-12T16:31:43.000Z","size":24,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T05:48:27.072Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/intrip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-29T20:48:42.000Z","updated_at":"2016-03-18T23:44:33.000Z","dependencies_parsed_at":"2022-08-20T23:10:57.019Z","dependency_job_id":null,"html_url":"https://github.com/intrip/jsonapi_errors","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intrip%2Fjsonapi_errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intrip%2Fjsonapi_errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intrip%2Fjsonapi_errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intrip%2Fjsonapi_errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/intrip","download_url":"https://codeload.github.com/intrip/jsonapi_errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246981166,"owners_count":20863828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T21:09:42.915Z","updated_at":"2025-04-03T10:15:52.322Z","avatar_url":"https://github.com/intrip.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSONAPIErrors\n\nJSONAPIErrors is a Framework agnostic gem to handle errors compliant to [JSON API standard](http://jsonapi.org).\nThe gem at the moment is integrated with Rails ActionController but if there is some interest we can integrate the gem\nwith other popular Ruby frameworks such as Sinatra or Lotus.\n\nThe idea is to handle errors with ruby exceptions. When an exception is raised the application tries to match the exception classname\nwith the matched exception list and if the exception is found renders a json response confirm to [JSONAPI errors standard](http://jsonapi.org/format/#errors).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'JSONAPI_errors'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install JSONAPI_errors\n\nThen\n```ruby\ninclude  JSONAPIErrors::Rails::Controller\n```\nin your application_controller.rb or\nin the controllers where you need to enable the gem.\n\n## Usage\n\nAdd an element to the \"JSONAPIErrors::Configuration.matches\" hash for every exception error you need to handle.\nHere is an example:\n```ruby\n JSONAPIErrors::Configuration.matches = {\n      # exception class name\n      \"JSONAPIErrors::MatchedException\" =\u003e {\n          #  a unique identifier for this particular occurrence of the problem.\n          id: \"1\",\n          # a links object that follows [JSON API ERRORS standard](http://jsonapi.org/format/#errors)\n          links: \"\",\n          # the HTTP status code applicable to this problem, expressed as a string value.\n          # this value is equal to the response status code generated\n          status: \"422\",\n          # an application-specific error code, expressed as a string value.\n          code: \"422\",\n          # A short, human-readable summary of the problem\n          title: \"Title\",\n          # a human-readable explanation specific to this occurrence of the problem\n          detail: \"Detail of the error\",\n          # an object containing references to the source of the error\n          source: \"/data\",\n          # A meta object containing non-standard meta-information about the error.\n          meta: {\"internal_error\" =\u003e {}}\n      }\n    }\n```\n\nThis package comes with a default configuration out of the box that handles all the rails default errors.\nBy default every exception that is not matched in the list is just raised up to the application, in order\nto handle not matched errors you need to set the catch_unhandled_exceptions attribute to true. if\ncatch_unhandled_exceptions is set to true given the following exception:\n```ruby\nStandardError.new(\"msg\")\n```\nyou get this error response:\n\n```\n{\n    errors:[\n        {\n            title: \"Unhandled exception\",\n            detail: \"The Exception: StandardError msg. is not handled in configuration.matches.\",\n            status: \"500\"\n        }\n    ]\n}\n```\n\nBelow here you can find a complete example\n```ruby\nJSONAPIErrors::Configuration.cofigure do |config|\nconfig.matches  = {\n      ###\n      # ActiveRecord exceptions\n      ###\n      \"ActiveRecord::RecordInvalid\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"SubclassNotFound\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"AssociationTypeMismatch\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"SerializationTypeMismatch\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"AdapterNotSpecified\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"AdapterNotFound\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"ConnectionNotEstablished\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"RecordNotFound\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"RecordNotSaved\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"RecordNotDestroyed\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"StatementInvalid\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"PreparedStatementInvalid\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"StaleObjectError\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"ConfigurationError\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"ReadOnlyRecord\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"Rollback\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"DangerousAttributeError\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"AttributeAssignmentError\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"MultiparameterAssignmentErrors\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"UnknownPrimaryKey\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"ImmutableRelation\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      },\n      \"TransactionIsolationError\" =\u003e {\n          status: \"422\",\n          code: \"422\"\n      }\n  }\n\n  # set true in order to  catch not matched exceptions\n  config.catch_unhandled_exceptions = false\nend\n```\n\nPut this file in a rails initializer in order to make it work as expected.\n\n\n## Code Status\n\n[![Build Status](https://travis-ci.org/intrip/jsonapi_errors.svg?branch=master)](https://github.com/intrip/jsonapi_errors)\n\n## Contributing\n\n1. Fork it ( https://github.com/intrip/JSONAPI_errors/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintrip%2Fjsonapi_errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintrip%2Fjsonapi_errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintrip%2Fjsonapi_errors/lists"}