Commit f2eb95f0 authored by Ash McKenzie's avatar Ash McKenzie

HTTPHelper fix requires, add/use status constants

parent 25e751e9
require 'net/http'
require 'openssl'
require_relative 'gitlab_config'
require_relative 'httpunix'
module HTTPHelper
READ_TIMEOUT = 300
HTTP_SUCCESS = '200'.freeze
HTTP_MULTIPLE_CHOICES = '300'.freeze
HTTP_UNAUTHORIZED = '401'.freeze
HTTP_NOT_FOUND = '404'.freeze
HTTP_SUCCESS_LIKE = [HTTP_SUCCESS, HTTP_MULTIPLE_CHOICES].freeze
class ApiUnreachableError < StandardError; end
class NotFound < StandardError; end
......@@ -78,7 +91,7 @@ module HTTPHelper
$logger.info('finished HTTP request', method: method.to_s.upcase, url: url, duration: Time.new - start_time)
end
if response.code == "200"
if HTTP_SUCCESS_LIKE.include?(response.code)
$logger.debug('Received response', code: response.code, body: response.body)
else
$logger.error('Call failed', method: method.to_s.upcase, url: url, code: response.code, body: response.body)
......@@ -111,7 +124,7 @@ module HTTPHelper
end
def secret_token
@secret_token ||= File.read config.secret_file
@secret_token ||= File.read(config.secret_file)
end
def read_timeout
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment