Permalink
Browse files

custom error pages

  • Loading branch information...
Raekye committed Sep 27, 2014
1 parent 44c1265 commit 2e1ba143dffaf7dc25fb974f82e6a0473147a725
@@ -14,6 +14,18 @@ Please check it out and help improve it too!
### Contributing
Pull requests are welcome!

#### Tests

1. Start Sidekiq: `RAILS_ENV=test ./env.sh sidekiq`
1. Run `./env.sh rake test` (parallel to Sidekiq).
1. Will create servers using the Digital Ocean api token from "env.sh".
1. If nothing fails tests should delete everything they create.

- Because there's a lot of infrastructure (see below, "Technical details"), sometimes tests will fail for random reasons
- I have not found a good workaround for this
- Run `RAILS_ENV=test ./env.sh rails [s|c]` to run the server or console (respectively) in test mode
- Note: the test server does not automatically reload source files when you edit them. You must restart the server

#### Setting up your development environment
You should have a Unix/Linux system.
The following instructions were made for Fedora 20, but the steps should be similar on other distributions.
@@ -63,23 +75,19 @@ Alternatively, you can edit `config/database.yml` to use a different user.
- Checks if the postgresql user matches the operating system user
- Create a postgres user with your OS username (example uses "gamocosm")
- Add `local all gamocosm peer`. Note: an entry `local all all peer` may already exist, so you won't have to do anything
- ident
- Same as `peer` but for network connections
- md5
- Client supplies an MD5-encrypted password
- Add `local all gamocosm md5`

#### Tests
Start Sidekiq: `RAILS_ENV=test ./env.sh sidekiq`
Run `./env.sh rake test` (parallel to Sidekiq).
Will create servers using the Digital Ocean api token from "env.sh".
If nothing fails tests should delete everything they create.

#### Technical details
Hmmmm.

##### Data
Gamocosm has a lot of infrastructure; there's Digital Ocean's API, there're the Digital Ocean servers/droplets, there's Minecraft and its wrapper on the servers, the Gamocosm rails server, and the Gamocosm sidekiq worker.
Avoid state whenever possible. Less data equals less chance of corruption.
Idempotency is good.
- Gamocosm has a lot of infrastructure: Digital Ocean's API, Digital Ocean servers/droplets, Minecraft and the server wrapper, the Gamocosm rails server, and the Gamocosm sidekiq worker
- Avoid state whenever possible; less chance of corruption with less data
- Idempotency is good

##### Error handling

@@ -103,6 +111,7 @@ Idempotency is good.
#### Other useful stuff
- Development/test user (from `db/seed.rb`): email "test@test.com", password "1234test", has the Digital Ocean api token from `env.sh`
- The Sidekiq web interface is mounted at `/sidekiq`
- Sidekiq doesn't automatically reload source files when you edit them. You must restart it for changes to take effect
- New Relic RPM is available in developer mode at `/newrelic`
- Run the console: `./env.sh rails c`
- Reset the database: `./env.sh rake db:reset`
@@ -79,4 +79,16 @@ def tos

def digital_ocean_setup
end

def not_found
render status: 404
end

def unacceptable
render status: 422
end

def internal_error
render status: 500
end
end
@@ -0,0 +1,16 @@
<div class="row">
<div class="col-sm-12">
<h1>We're sorry, but something went wrong</h1>
<p>
This has been logged and we'll take a look at it.
If it's urgent, or this keeps happening, please <%= link_to 'let us know about it!', issues_path %>
</p>
<hr />
<ul>
<li><%= link_to 'Home page', root_path %></li>
<% if user_signed_in? %>
<li><%= link_to 'My servers', minecrafts_path %></li>
<% end %>
</ul>
</div>
</div>
@@ -0,0 +1,16 @@
<div class="row">
<div class="col-sm-12">
<h1>This page does not exist</h1>
<p>
You may have mistyped the address or the page may have moved.
If you think this is an error, please <%= link_to 'let us know about it!', issues_path %>
</p>
<hr />
<ul>
<li><%= link_to 'Home page', root_path %></li>
<% if user_signed_in? %>
<li><%= link_to 'My servers', minecrafts_path %></li>
<% end %>
</ul>
</div>
</div>
@@ -0,0 +1,16 @@
<div class="row">
<div class="col-sm-12">
<h1>The change you wanted was rejected</h1>
<p>
Maybe you tried to change something you didn't have access to.
If you think this is an error, please <%= link_to 'let us know about it!', issues_path %>
</p>
<hr />
<ul>
<li><%= link_to 'Home page', root_path %></li>
<% if user_signed_in? %>
<li><%= link_to 'My servers', minecrafts_path %></li>
<% end %>
</ul>
</div>
</div>
@@ -22,6 +22,7 @@ class Application < Rails::Application

# Custom
config.cache_store = :dalli_store, 'localhost', { namespace: "gamocosm-#{Rails.env}", expires_in: 24.hours, compress: true }
config.exceptions_app = self.routes
end

def self.minecraft_jar_default_url
@@ -10,7 +10,7 @@
config.eager_load = false

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.consider_all_requests_local = ENV['CONSIDER_ALL_REQUESTS_LOCAL'] != 'false'
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
@@ -10,6 +10,10 @@

get '/digital_ocean_setup', to: 'pages#digital_ocean_setup', as: :digital_ocean_setup

get '/404', to: 'pages#not_found'
get '/422', to: 'pages#unacceptable'
get '/500', to: 'pages#internal_error'

match '/wiki' => redirect('https://github.com/Gamocosm/Gamocosm/wiki'), as: :wiki, via: :get
match '/issues' => redirect('https://github.com/Gamocosm/Gamocosm/issues'), as: :issues, via: :get
match '/source' => redirect('https://github.com/Gamocosm/Gamocosm'), as: :source, via: :get
@@ -27,7 +31,7 @@
match '/pricing' => redirect('https://www.digitalocean.com/pricing/'), as: :digital_ocean_pricing, via: :get
match '/index' => redirect(Gamocosm.digital_ocean_referral_link), as: :digital_ocean_index, via: :get
match '/help' => redirect('https://www.digitalocean.com/help/'), as: :digital_ocean_help, via: :get
match '/control_panel' => redirect('https://cloud.digitalocean.com/login'), as: :digital_ocean_control_panel, via: :get
match '/control_panel' => redirect('https://cloud.digitalocean.com'), as: :digital_ocean_control_panel, via: :get
end

Sidekiq::Web.use Rack::Auth::Basic, 'Protected Area' do |u, p|
@@ -13,4 +13,10 @@
user.password_confirmation = user.password
user.digital_ocean_api_key = Gamocosm.digital_ocean_api_key
user.save!

user = User.new
user.email = 'test2@test.com'
user.password = '1234test'
user.password_confirmation = user.password
user.save!
end

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

0 comments on commit 2e1ba14

Please sign in to comment.