Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airbrake: unexpected code (405). Body: Method Not Allowed #80

Closed
brand-it opened this issue May 11, 2016 · 3 comments
Closed

Airbrake: unexpected code (405). Body: Method Not Allowed #80

brand-it opened this issue May 11, 2016 · 3 comments
Labels

Comments

@brand-it
Copy link

brand-it commented May 11, 2016

This error above was caused by something that took me a while to figure out. I am running airbrake (5.0.5) on my application and found that this error comes up when you are setting the project_id and the project_key to blank values.

File: config/initializers/airbrake.rb

Airbrake.configure do |c|
  c.project_id = ''
  c.project_key = ''
rake airbrake:deploy USERNAME=my_user ENVIRONMENT=staging REVISION=revision REPOSITORY=github_repo VERSION=1

results from command

Request URI: /api/v4/projects/deploys?key=
Req: #<Net::HTTP::Post POST>
Endpoint: #<URI::HTTPS https://airbrake.io/api/v4/projects/deploys?key=>
Notice: {:environment=>"alpha", :username=>"my_user", :revision=>"revision", :repository=>"github_repo", :version=>"1"}
Response: #<Net::HTTPMethodNotAllowed 405 Method Not Allowed readbody=true>
E, [2016-05-11T11:55:50.492599 #97422] ERROR -- : **Airbrake: unexpected code (405). Body: Method Not Allowed

My Understanding of Results

Most of what I was seeing now makes sense. based off what I see above I get why it resulted in the 405. Because the project_id is not present it changes the URL. So a 405 is exactly what you expect. when you don't have a project_id

Request URI: /api/v4/projects/{project_id}/deploys?key={project_key}
Req: #<Net::HTTP::Post POST>
Endpoint: #<URI::HTTPS https://airbrake.io/api/v4/projects/{project_id}/deploys?key=39f22e0d8d5f97df880bd62567b0f2b6>
Notice: {:environment=>"alpha", :username=>"my_user", :revision=>"d2eae2dd353f67f7c95f97b7fcbe23ff170382c6", :repository=>"github_repo", :version=>"1"}
Response: #<Net::HTTPCreated 201 Created readbody=true>

Possible Solution

I think a good idea would be to add a check to make sure that the project_id and project key are present before you send the post. If not present warn the user but perform the action anyway. As you could be in the test environment or in the development environment. However there is much more to take into account as you can run the rake airbrake:deploy using RAILS_ENV=development and ENVIRONMENT=staging. So might be be also a solution to only warn if the ENVIRONMENT that you are deploying to is not in the ignore_environemnts varable.

c.ignore_environments = %w(test development)

require 'airbrake/sidekiq/error_handler'

airbrake_yml = Rails.root.join('config', 'airbrake.yml')
if File.exist?(airbrake_yml)
  config = YAML.load_file(airbrake_yml)
  puts '------------------------- Deprecation Warning -------------------------'
  puts(
    'Deprecation Warning: airbrake.yml is being removed please use .env '\
    'with AIRBRAKE_PROJECT_ID & AIRBRAKE_PROJECT_KEY'
  )
  puts '------------------------- Deprecation Warning -------------------------'
  project_key = config[:project_key]
  project_id = config[:project_id]
end

project_key = (ENV['AIRBRAKE_PROJECT_KEY'] || project_key).to_s
project_id = (ENV['AIRBRAKE_PROJECT_ID'] || project_id).to_s
# I found that there is a lot of confusing error messages when keys are blank
# To solve this we are placing a warning to the user so that they can
# address the problem. However the warning does not apply when you are testing
# as there is no use case currently that would require the application to talk
# to airbrake when in test mode
unless Rails.env.test?
  puts 'WARN: Airbrake Project key is blank' if project_key.blank?
  puts 'WARN: Airbrake Project id is blank' if project_id.blank?
end

https://github.com/airbrake/airbrake-ruby/blob/master/lib/airbrake-ruby/config.rb#L100
I am think here on the endpoint method might be the best spot to raise the warning as it seams to be the point in which the data is required to work correctly.

@kyrylo kyrylo added the Bug label May 13, 2016
kyrylo added a commit that referenced this issue Jun 3, 2016
Fixes #80 (Airbrake: unexpected code (405). Body: Method Not Allowed)
and many other complains of people who are confused by the current
behaviour when we raise an error when they ignore current environment.
kyrylo added a commit that referenced this issue Jun 3, 2016
Fixes #80 (Airbrake: unexpected code (405). Body: Method Not Allowed)
and many other complains of people who are confused by the current
behaviour when we raise an error when they ignore current environment.
kyrylo added a commit that referenced this issue Jun 3, 2016
Fixes #80 (Airbrake: unexpected code (405). Body: Method Not Allowed)
and many other complains of people who are confused by the current
behaviour when we raise an error when they ignore current environment.
kyrylo added a commit that referenced this issue Jun 6, 2016
Fixes #80 (Airbrake: unexpected code (405). Body: Method Not Allowed)
and many other complains of people who are confused by the current
behaviour when we raise an error when they ignore current environment.
@kyrylo kyrylo closed this as completed in #87 Jun 6, 2016
@ivanovv
Copy link

ivanovv commented Mar 11, 2019

this started to happen again, with airbrake-ruby (4.1.0) in my Gemfile.lock

@kyrylo
Copy link
Contributor

kyrylo commented Mar 11, 2019

This issue is rather old and a lot has changed since then. Could you open a new one with your config details?

@ivanovv
Copy link

ivanovv commented Mar 11, 2019

opened airbrake/airbrake#931

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants