• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / allsearch_api / dc764cb3-fc9b-47a1-b010-56b68ecb28a7

01 Aug 2025 03:30PM UTC coverage: 99.514%. Remained the same
dc764cb3-fc9b-47a1-b010-56b68ecb28a7

push

circleci

web-flow
Merge pull request #384 from pulibrary/dependabot/bundler/nokogiri-1.18.9

Bump nokogiri from 1.18.8 to 1.18.9

1024 of 1029 relevant lines covered (99.51%)

92.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.88
/app/controllers/service_controller.rb
1
# frozen_string_literal: true
2

3
class ServiceController < ApplicationController
3✔
4
  rescue_from StandardError, with: :show_standard_error
3✔
5
  rescue_from Timeout::Error, Errno::ECONNRESET, Net::ProtocolError, with: :show_http_error
3✔
6
  rescue_from AllsearchError, with: :show_allsearch_error
3✔
7
  rescue_from ActionController::ParameterMissing, with: :show_query_error
3✔
8
  rescue_from URI::InvalidURIError, with: :rescue_from_error
3✔
9
  rescue_from ArgumentError, with: :rescue_from_error
3✔
10
  attr_reader :query
3✔
11

12
  def show
3✔
13
    @query = service.new(query_terms: query_params)
159✔
14

15
    render json: query.our_response
136✔
16
  end
17

18
  private
3✔
19

20
  attr_reader :service
3✔
21

22
  def query_params
3✔
23
    params.require(:query).gsub(/[#{Regexp.escape(special_characters)}]/, ' ')
159✔
24
          .gsub(/\s+/, ' ')
25
          .strip
26
  end
27

28
  def show_standard_error(exception)
3✔
29
    Honeybadger.notify exception
×
30
    render_error(problem: 'APPLICATION_ERROR',
×
31
                 message: "This application threw #{exception.class}",
32
                 status: :internal_server_error)
33
  end
34

35
  # :reek:FeatureEnvy
36
  def show_http_error(exception)
3✔
37
    Honeybadger.notify exception
1✔
38
    render_error(problem: 'UPSTREAM_ERROR',
1✔
39
                 message: "Query to upstream failed with #{exception.class}, message: #{exception.message}",
40
                 status: :internal_server_error)
41
  end
42

43
  # :reek:FeatureEnvy
44
  def show_allsearch_error(exception)
3✔
45
    Honeybadger.notify exception
6✔
46
    render_error(problem: exception.problem,
6✔
47
                 message: exception.message,
48
                 status: :internal_server_error)
49
  end
50

51
  def show_query_error
3✔
52
    # We don't report these to Honeybadger, since the system is working as
53
    # expected in these cases by telling the user they need to enter a query.
54
    render_error(problem: 'QUERY_IS_EMPTY',
20✔
55
                 message: 'The query param must contain non-whitespace characters.',
56
                 status: :bad_request)
57
  end
58

59
  def rescue_from_error
3✔
60
    @query = service.new(query_terms: URI.encode_uri_component(query_params))
×
61

62
    render json: query.our_response
×
63
  end
64

65
  def render_error(problem:, message:, status:)
3✔
66
    render json: { error: {
27✔
67
      problem:,
68
      message:
69
    } }, status:
70
  end
71

72
  def special_characters
3✔
73
    '{}#!</>'
139✔
74
  end
75
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc