Skip to content

Commit

Permalink
fix the error reporting seek4science#1691
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Dec 13, 2023
1 parent 6fffb9e commit cd2a7fd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/controlled_vocabs.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ CVTerms = {
$j('#add-term-button-row').before($j(newTerm));
},
// reports the error when the ajax method to fetch the terms is unsuccessful
reportFetchError: function (json) {
var error_message = json.errors[0].details;
reportFetchError: function (error_message) {
// let json = JSON.parse(response);
// const error_message = json.errors[0].details;
$j('div#fetch-error-message').text("An error occurred fetching the terms: " + error_message);
$j('div#fetch-error-message').show();
},
Expand Down Expand Up @@ -164,7 +165,7 @@ CVTerms = {
CVTerms.handleOntologyTermsHTMLResponse(resp);
},
error: function (resp) {
CVTerms.reportFetchError(resp.responseJSON);
CVTerms.reportFetchError(resp.responseText);
},
complete: function () {
$j('#fetch-terms-spinner').spinner('remove');
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/sample_controlled_vocabs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ def fetch_ols_terms_html
@terms = client.all_descendants(source_ontology, root_uri)
@terms.reject! { |t| t[:iri] == root_uri } unless params[:include_root_term] == '1'
error_msg = "There are no descendant terms to populate the list." unless @terms.present?
# rescue StandardError => e
# error_msg = e.message
rescue StandardError => e
error_msg = e.message
end

respond_to do |format|
if error_msg
format.html { render json: { errors: [{ details: error_msg }] }, status: :unprocessable_entity }
format.html { render plain: error_msg , status: :unprocessable_entity }
else
format.html { render layout: false }
end
Expand Down
37 changes: 31 additions & 6 deletions test/functional/sample_controlled_vocabs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class SampleControlledVocabsControllerTest < ActionController::TestCase
end
end

test 'fetch ols terms with root term included' do
test 'fetch ols terms as JSON with root term included' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do
Expand All @@ -285,7 +285,7 @@ class SampleControlledVocabsControllerTest < ActionController::TestCase
end
end

test 'fetch ols terms without root term included' do
test 'fetch ols terms as JSON without root term included' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do
Expand All @@ -302,7 +302,7 @@ class SampleControlledVocabsControllerTest < ActionController::TestCase
end
end

test 'fetch ols terms with wrong URI' do
test 'fetch ols terms as JSON with wrong URI' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_bad_term') do
Expand All @@ -316,14 +316,39 @@ class SampleControlledVocabsControllerTest < ActionController::TestCase
end
end

test 'fetch ols terms as html' do
test 'fetch ols terms as HTML with wrong URI' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do
VCR.use_cassette('ols/fetch_obo_bad_term') do
get :fetch_ols_terms_html, params: { source_ontology_id: 'go',
root_uri: 'http://purl.obolibrary.org/obo/GO_0090395',
root_uri: 'http://purl.obolibrary.org/obo/banana',
include_root_term: '1' }

assert_response :unprocessable_entity
assert_equal '404 Not Found', response.body
end
end

test 'fetch ols terms as HTML with root term included' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do
get :fetch_ols_terms_html, params: { source_ontology_id: 'go',
root_uri: 'http://purl.obolibrary.org/obo/GO_0090395',
include_root_term: '1' }

assert_response :success
pp response.body
end
end

test 'fetch ols terms as HTML without root term included' do
person = FactoryBot.create(:person)
login_as(person)
VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do
get :fetch_ols_terms_html, params: { source_ontology_id: 'go',
root_uri: 'http://purl.obolibrary.org/obo/GO_0090395' }

assert_response :success
pp response.body
end
Expand Down

0 comments on commit cd2a7fd

Please sign in to comment.