Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Dynamically handle exceptions and render a structured JSON response to client applications. Formerly (Memereply sad pepe)
Add this line to your application's Gemfile:
gem 'marr'
And then execute:
$ bundle
Or install it yourself as:
$ gem install marr
{
"errors": {
"id": "6CA01AF9E592595F",
"code": "UnprocessableGroup",
"title": "Request can not be processed.",
"detail": "The Group can not be saved. Invalid or missing data.",
"meta": {
"object_errors": [
{
"pointer": "owner",
"detail": "Owner can't be blank"
},
{
"pointer": "name",
"detail": "Name can't be blank"
}
],
"trace_id": "6CA01AF9E592595F"
}
}
}
There is a method automatically created for each each class that inherits from Marr::ApiError. The method is preprended with 'raise'.
raise_unprocessable_group_error
You can also pass in options to your method for a more robust response:
raise_unprocessable_group_error(controller: self, subcode: :missing_data, object: @group)
Configure the gem. For the gem to recognize the descendant classes you have to provide the name space the errors are under.
Marr.configure do |config|
config.namespaces = ['Api::V1::Errors']
config.trace_id_length = 16
end
Create a new Error that inherits from the ApiError class. The class needs to be under the configured name space. NOTE: The message
method must be implemented.
module Api
module V1
module Errors
class UnprocessableGroup < ::Marr::ApiError
def message
"Request can not be processed."
end
def subcodes
super({
missing_data: 'The Group can not be saved. Invalid or missing data.',
})
end
end
end
end
end
Include the ErrorEngine module in your base api class
include ::Marr::Api::ErrorEngine
Next rescue all your api errors. This method could be in your base api class.
rescue_from 'Marr::ApiError' do |exception|
render exception.render, status: exception.status
end
If you are custom rendering using a gem like Jbuilder you can do something like this:
# you would overide the custom_render in your class to return the file path you want to use
#=> 'api/internal/v1/errors/error'
rescue_from 'Marr::ApiError' do |error|
@error = error
render @error.render, status: @error.status
end
FAQs
Unknown package
We found that marr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.