diff --git a/.travis.yml b/.travis.yml
index 9227630..8351a9d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,7 @@ rvm:
addons:
chrome: stable
before_script:
- - sh -e /etc/init.d/xvfb start
+ - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
diff --git a/app/controllers/apitome/docs_controller.rb b/app/controllers/apitome/docs_controller.rb
index e6ad09a..7f25fb4 100644
--- a/app/controllers/apitome/docs_controller.rb
+++ b/app/controllers/apitome/docs_controller.rb
@@ -80,14 +80,19 @@ def rendered_markdown(string)
end
def formatted_body(body, type)
+ return body if body == " "
+ return body if body == "[binary data]" # see https://github.com/zipmark/rspec_api_documentation/blob/560c3bdc7bd5581e7c223334390221ecfc910be8/lib/rspec_api_documentation/client_base.rb#L88-L96
if type =~ /json/ && body.present?
JSON.pretty_generate(JSON.parse(body))
else
body
end
- rescue JSON::ParserError
- return body if body == " "
- raise JSON::ParserError
+ rescue => e
+ if Apitome.configuration.formatted_body_error_handler
+ Apitome.configuration.formatted_body_error_handler.call(e, body, type)
+ else
+ raise
+ end
end
def param_headers(params)
diff --git a/app/views/apitome/docs/_example.html.erb b/app/views/apitome/docs/_example.html.erb
index 496e494..0ef31e1 100644
--- a/app/views/apitome/docs/_example.html.erb
+++ b/app/views/apitome/docs/_example.html.erb
@@ -8,15 +8,26 @@
">
<%= t(:request, scope: :apitome) %>
+ <% begin %>
<%= render partial: 'apitome/docs/route', locals: {request: request, index: index} %>
<%= render partial: 'apitome/docs/headers', locals: {request: request, index: index, headers: request['request_headers']} %>
<%= render partial: 'apitome/docs/query', locals: {request: request, index: index} unless request['request_query_parameters'].empty? %>
<%= render partial: 'apitome/docs/body', locals: {request: request, index: index, body: request['request_body'], type: request['request_content_type']} if request['request_body'] %>
<%= render partial: 'apitome/docs/curl', locals: {request: request, index: index} if request['curl'] %>
+ <%
+ rescue => e
+ if Apitome.configuration.example_error_handler
+ Apitome.configuration.example_error_handler.call(e, "request", request)
+ else
+ raise
+ end
+ end
+ %>
<%= t(:response, scope: :apitome) %>
+ <% begin %>
<%- if Apitome.configuration.simulated_response %>
<%= link_to('Simulated Response', simulated_path(example[:link])) if example[:link].present? %>
<%- end %>
@@ -24,6 +35,15 @@
<%= render partial: 'apitome/docs/status', locals: {request: request, index: index} %>
<%= render partial: 'apitome/docs/headers', locals: {request: request, index: index, headers: request['response_headers']} %>
<%= render partial: 'apitome/docs/body', locals: {request: request, index: index, body: request['response_body'], type: request['response_content_type']} if request['response_body'] %>
+ <%
+ rescue => e
+ if Apitome.configuration.example_error_handler
+ Apitome.configuration.example_error_handler.call(e, "response", request)
+ else
+ raise
+ end
+ end
+ %>
<% end %>
diff --git a/lib/apitome/configuration.rb b/lib/apitome/configuration.rb
index 86bf60a..cda4e39 100644
--- a/lib/apitome/configuration.rb
+++ b/lib/apitome/configuration.rb
@@ -21,6 +21,8 @@ class Configuration
:http_basic_authentication,
:precompile_assets,
:simulated_response,
+ :formatted_body_error_handler,
+ :example_error_handler,
])
@@mount_at = "/api/docs"
@@ -39,6 +41,8 @@ class Configuration
@@http_basic_authentication = nil
@@precompile_assets = true
@@simulated_response = true
+ @@formatted_body_error_handler = nil
+ @@example_error_handler = nil
def self.root=(path)
@@root = Pathname.new(path.to_s) if path.present?
diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js
new file mode 100644
index 0000000..78eff0c
--- /dev/null
+++ b/spec/dummy/app/assets/config/manifest.js
@@ -0,0 +1,3 @@
+//= link apitome/application.css
+//= link apitome/application.js
+//= link apitome/highlight_themes/default.css