Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ dhp:
digital_forms_api:
base_url: <%= ENV['digital_forms_api__base_url'] %>
breakers_error_threshold: 80
cache_ttl:
schema: 1440 # minutes == 24 hours
template: 1440 # minutes == 24 hours
include_request: false
jwt_secret: <%= ENV['digital_forms_api__jwt_secret'] %>
mock: false
Expand Down
3 changes: 3 additions & 0 deletions config/settings/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ dhp:
digital_forms_api:
base_url: https://digital-forms-api-fake.fake.bip.va.gov/api/v1/rest/
breakers_error_threshold: 80
cache_ttl:
schema: 1
template: 1
include_request: false
jwt_secret: fake-secret
mock: false
Expand Down
3 changes: 3 additions & 0 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ dhp:
digital_forms_api:
base_url: https://digital-forms-api-fake.fake.bip.va.gov/api/v1/rest/
breakers_error_threshold: 80
cache_ttl:
schema: 1
template: 1
include_request: false
jwt_secret: fake-secret
mock: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'digital_forms_api/service/forms'
require 'digital_forms_api/service/submissions'
require 'digital_forms_api/service/templates'

module DigitalFormsApi
# The Fully Digital Forms controller that handles fetching form submissions and templates
Expand All @@ -17,7 +17,7 @@ def show
return render json: { error: 'Forbidden' }, status: :forbidden
end

template = forms_service.template('21-686c')
template = templates_service.template('21-686c')
render json: { submission: submission.body['envelope']['payload'],
template: template['formTemplate']['formTemplate']['21-686c'] }
rescue Common::Client::Errors::ClientError => e
Expand All @@ -27,9 +27,6 @@ def show
Rails.logger.error('Digital Forms API - error status from BIP Forms API', { status: e.status })
render json: { error: 'Internal server error' }, status: :internal_server_error
end
rescue => e
Rails.logger.error('Digital Forms API - unexpected error', { message: e.message })
render json: { error: 'Internal server error' }, status: :internal_server_error
Comment on lines -30 to -32
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any additional errors are captured by ApplicationsController, so this is unneeded
app/controllers/application_controller.rb
app/controllers/concerns/exception_handling.rb

end

private
Expand All @@ -40,8 +37,8 @@ def check_flipper_flag
end

# Instantiate service for interacting with the /forms endpoints
def forms_service
DigitalFormsApi::Service::Forms.new
def templates_service
DigitalFormsApi::Service::Templates.new
end

# Instantiate service for interacting with the /submissions endpoints
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require 'digital_forms_api/service/base'

module DigitalFormsApi
module Service
# Schemas API
class Schemas < Base
# Cache TTL values for form schemas
CACHE_TTL = (Settings.digital_forms_api.cache_ttl.schema.to_i || 5).minutes

# Build the cache key for a given form template.
def self.cache_key(form_id)
"digital_forms_api:schema:#{form_id}"
end

# @see #schema
def self.get(form_id)
new.schema(form_id)
end

# GET a form schema (with caching)
# Caches only the parsed response body to avoid persisting sensitive
# request metadata (e.g., Authorization headers) from the Faraday::Env.
def schema(form_id)
cache_key = self.class.cache_key(form_id)

# @see DigitalFormsApi::Service::Base#context
tags = { form_id: }
@context = tags.merge(tags:)

Rails.cache.fetch(cache_key, expires_in: CACHE_TTL, race_condition_ttl: 10.seconds) do
perform(:get, "forms/#{form_id}/schema", {}, {}).body
end
end

private

# @see DigitalFormsApi::Service::Base#endpoint
def endpoint
'schemas'
end

# end Schemas
end

# end Service
end

# end DigitalFormsApi
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def retrieve(submission_id)
perform :get, "submissions/#{submission_id}", {}, {}
end

# GET get a form submission by document id
# Retrieve details for a previously submitted form using the associated CE document ID
def by_document_id(document_id)
perform :get, "submissions/by-document-id/#{document_id}", {}, {}
end

private

# @see DigitalFormsApi::Service::Base#endpoint
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require 'digital_forms_api/service/base'

module DigitalFormsApi
module Service
# Templates API
class Templates < Base
# Cache TTL values for form templates
CACHE_TTL = (Settings.digital_forms_api.cache_ttl.template.to_i || 5).minutes

# Build the cache key for a given form template.
def self.cache_key(form_id)
"digital_forms_api:template:#{form_id}"
end

# @see #template
def self.get(form_id)
new.template(form_id)
end

# GET a form template (with caching)
# Caches only the parsed response body to avoid persisting sensitive
# request metadata (e.g., Authorization headers) from the Faraday::Env.
def template(form_id)
cache_key = self.class.cache_key(form_id)

# @see DigitalFormsApi::Service::Base#context
tags = { form_id: }
@context = tags.merge(tags:)

Rails.cache.fetch(cache_key, expires_in: CACHE_TTL, race_condition_ttl: 10.seconds) do
perform(:get, "forms/#{form_id}/template", {}, {}).body
end
end

private

# @see DigitalFormsApi::Service::Base#endpoint
def endpoint
'templates'
end

# end Templates
end

# end Service
end

# end DigitalFormsApi
end
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,16 @@ def retrieve_submission!
expect(response).to have_http_status(:forbidden)
end
end

context 'when a non-FormsAPI error occurs' do
let(:cassette) { 'retrieve_686c' }

it 'returns a 500 error' do
expect_any_instance_of(DigitalFormsApi::SubmissionsController).to receive(:show).and_raise RuntimeError

retrieve_submission!
expect(response).to have_http_status(:internal_server_error)
end
end
end
end
Loading
Loading