Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

baywatch

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baywatch

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

Baywatch

Installation

Add this line to your application's Gemfile:

gem 'baywatch'

And then execute:

$ bundle

Usage

Declarative way to error handling inside controller


  class UsersController < ApplicationController
    include Baywatch::Rescue

    # By default will handle([ Errno::ECONNREFUSED, Errno::ECONNRESET ])
    service_down do |on|      
      on.index do
        flash[:error] = "Sorry, the service is not working properly"
      end
      on.create do 
        flash[:error] = "Sorry, we cannot save right now"
        flash.keep(:error)
        redirect root_url
      end
    end
    
    def index
      @users = UserRemoteService.all
    end
    
    def create
      UserRemoteService.create(params[:user])
    end
    
  end
  

Using #only to use the same behavior to many actions.


  class UserController < ApplicationController
    include Baywatch::Rescue

    service_down do |on|      
      on.only :index, :create do
        flash[:error] = "Sorry, the service is not working properly"
        redirect_to root_url
      end
    end
    
    def index
      @users = UserRemoteService.all
    end
    
    def create
      UserRemoteService.create(params[:user])
    end
    
  end
  

TODO

Handle Contextual Exception
 service_down do |on|
 
   on.edit(ActiveRecord::RecordNotFound)
     flash[:error] = "Not Found"
     redirect_to root_url
   end
   
   on.edit(Base::WhateverException)
     flash[:error] = "Whatever Message Here"
     MailAdministrator.send(:fail")
     redirect_to root_url
   end
 end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Cover with tests
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

FAQs

Package last updated on 28 Mar 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc