Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling of view service response #2211

Merged
merged 1 commit into from
Oct 25, 2023
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
147 changes: 77 additions & 70 deletions src/js/views/MetadataIndexView.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,85 +65,92 @@ define(['jquery',
encodeURIComponent(this.pid)+'")&rows=1&start=0&fl=*&wt=json';
var requestSettings = {
url: MetacatUI.appModel.get('queryServiceUrl') + query,
success: function(data, textStatus, xhr){
success: function (data, textStatus, xhr) {

if(data.response.numFound == 0){
try {

if( view.parentView && view.parentView.model ){
if (!data?.response?.numFound) {

//Show a "not indexed" message if there is system metadata but nothing in
// the index
if(view.parentView.model.get("systemMetadata")){
view.showNotIndexed();
}
//Show a "not found" message if there is no system metadata and no results in the index
else{
view.parentView.model.set("notFound", true);
view.parentView.showNotFound();
}
}
if (view.parentView && view.parentView.model) {

view.flagComplete();
}
else{
view.docs = data.response.docs;
//Show a "not indexed" message if there is system metadata but nothing in
// the index
if (view.parentView.model.get("systemMetadata")) {
view.showNotIndexed();
}
//Show a "not found" message if there is no system metadata and no results in the index
else {
view.parentView.model.set("notFound", true);
view.parentView.showNotFound();
}
}

_.each(data.response.docs, function(doc, i, list){
view.flagComplete();
}
else {
view.docs = data.response.docs;

//If this is a data object and there is a science metadata doc that describes it, then navigate to that Metadata View.
if((doc.formatType == "DATA") && (doc.isDocumentedBy && doc.isDocumentedBy.length)){
view.onClose();
MetacatUI.uiRouter.navigate("view/" + doc.isDocumentedBy[0], true);
return;
}
_.each(data.response.docs, function (doc, i, list) {

var metadataEl = $(document.createElement("section")).attr("id", "metadata-index-details"),
id = doc.id,
creator = doc.origin,
title = doc.title,
pubDate = doc.pubDate,
dateUploaded = doc.dateUploaded,
keys = Object.keys(doc),
docModel = new SolrResult(doc);

//Extract General Info details that we want to list first
var generalInfoKeys = ["title", "id", "abstract", "pubDate", "keywords"];
keys = _.difference(keys, generalInfoKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, generalInfoKeys, "General"));

//Extract Spatial details
var spatialKeys = ["site", "southBoundCoord", "northBoundCoord", "westBoundCoord", "eastBoundCoord"];
keys = _.difference(keys, spatialKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, spatialKeys, "Geographic Region"));

//Extract Temporal Coverage details
var temporalKeys = ["beginDate", "endDate"];
keys = _.difference(keys, temporalKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, temporalKeys, "Temporal Coverage"));

//Extract Taxonomic Coverage details
var taxonKeys = ["order", "phylum", "family", "genus", "species", "scientificName"];
keys = _.difference(keys, taxonKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, taxonKeys, "Taxonomic Coverage"));

//Extract People details
var peopleKeys = ["origin", "investigator", "contactOrganization", "project"];
keys = _.difference(keys, peopleKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, peopleKeys, "People and Associated Parties"));

//Extract Access Control details
var accessKeys = ["isPublic", "submitter", "rightsHolder", "writePermission", "readPermission", "changePermission", "authoritativeMN"];
keys = _.difference(keys, accessKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, accessKeys, "Access Control"));

//Add the rest of the metadata
$(metadataEl).append(view.formatAttributeSection(docModel, keys, "Other"));

view.$el.html(metadataEl);
//If this is a data object and there is a science metadata doc that describes it, then navigate to that Metadata View.
if ((doc.formatType == "DATA") && (doc.isDocumentedBy && doc.isDocumentedBy.length)) {
view.onClose();
MetacatUI.uiRouter.navigate("view/" + doc.isDocumentedBy[0], true);
return;
}

view.flagComplete();
});
var metadataEl = $(document.createElement("section")).attr("id", "metadata-index-details"),
id = doc.id,
creator = doc.origin,
title = doc.title,
pubDate = doc.pubDate,
dateUploaded = doc.dateUploaded,
keys = Object.keys(doc),
docModel = new SolrResult(doc);

//Extract General Info details that we want to list first
var generalInfoKeys = ["title", "id", "abstract", "pubDate", "keywords"];
keys = _.difference(keys, generalInfoKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, generalInfoKeys, "General"));

//Extract Spatial details
var spatialKeys = ["site", "southBoundCoord", "northBoundCoord", "westBoundCoord", "eastBoundCoord"];
keys = _.difference(keys, spatialKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, spatialKeys, "Geographic Region"));

//Extract Temporal Coverage details
var temporalKeys = ["beginDate", "endDate"];
keys = _.difference(keys, temporalKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, temporalKeys, "Temporal Coverage"));

//Extract Taxonomic Coverage details
var taxonKeys = ["order", "phylum", "family", "genus", "species", "scientificName"];
keys = _.difference(keys, taxonKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, taxonKeys, "Taxonomic Coverage"));

//Extract People details
var peopleKeys = ["origin", "investigator", "contactOrganization", "project"];
keys = _.difference(keys, peopleKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, peopleKeys, "People and Associated Parties"));

//Extract Access Control details
var accessKeys = ["isPublic", "submitter", "rightsHolder", "writePermission", "readPermission", "changePermission", "authoritativeMN"];
keys = _.difference(keys, accessKeys);
$(metadataEl).append(view.formatAttributeSection(docModel, accessKeys, "Access Control"));

//Add the rest of the metadata
$(metadataEl).append(view.formatAttributeSection(docModel, keys, "Other"));

view.$el.html(metadataEl);

view.flagComplete();
});

}
} catch (e) {
console.log("Error parsing Solr response: " + e);
console.log("Solr response: " + data);
view.parentView.showNotFound();
}
},
error: function(){
Expand Down
62 changes: 34 additions & 28 deletions src/js/views/MetadataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,47 +386,53 @@ define(['jquery',
var loadSettings = {
url: endpoint,
success: function (response, status, xhr) {
try {

//If the user has navigated away from the MetadataView, then don't render anything further
if (MetacatUI.appView.currentView != viewRef)
return;

//Our fallback is to show the metadata details from the Solr index
if (status == "error")
viewRef.renderMetadataFromIndex();
else {
//Check for a response that is a 200 OK status, but is an error msg
if ((response.length < 250) && (response.indexOf("Error transforming document") > -1) && viewRef.model.get("indexed")) {
viewRef.renderMetadataFromIndex();
//If the user has navigated away from the MetadataView, then don't render anything further
if (MetacatUI.appView.currentView != viewRef)
return;
}
//Mark this as a metadata doc with no stylesheet, or one that is at least different than usual EML and FGDC
else if ((response.indexOf('id="Metadata"') == -1)) {
viewRef.$el.addClass("container no-stylesheet");

if (viewRef.model.get("indexed")) {
//Our fallback is to show the metadata details from the Solr index
if (status == "error" || !response || typeof response !== "string")
viewRef.renderMetadataFromIndex();
else {
//Check for a response that is a 200 OK status, but is an error msg
if ((response.length < 250) && (response.indexOf("Error transforming document") > -1) && viewRef.model.get("indexed")) {
viewRef.renderMetadataFromIndex();
return;
}
}
//Mark this as a metadata doc with no stylesheet, or one that is at least different than usual EML and FGDC
else if ((response.indexOf('id="Metadata"') == -1)) {
viewRef.$el.addClass("container no-stylesheet");

if (viewRef.model.get("indexed")) {
viewRef.renderMetadataFromIndex();
return;
}
}

//Now show the response from the view service
viewRef.$(viewRef.metadataContainer).html(response);
//Now show the response from the view service
viewRef.$(viewRef.metadataContainer).html(response);

//If there is no info from the index and there is no metadata doc rendered either, then display a message
if (viewRef.$el.is(".no-stylesheet") && viewRef.model.get("archived") && !viewRef.model.get("indexed"))
viewRef.$(viewRef.metadataContainer).prepend(viewRef.alertTemplate({ msg: "There is limited metadata about this dataset since it has been archived." }));
//If there is no info from the index and there is no metadata doc rendered either, then display a message
if (viewRef.$el.is(".no-stylesheet") && viewRef.model.get("archived") && !viewRef.model.get("indexed"))
viewRef.$(viewRef.metadataContainer).prepend(viewRef.alertTemplate({ msg: "There is limited metadata about this dataset since it has been archived." }));

viewRef.alterMarkup();
viewRef.alterMarkup();

viewRef.trigger("metadataLoaded");
viewRef.trigger("metadataLoaded");

//Add a map of the spatial coverage
if (gmaps) viewRef.insertSpatialCoverageMap();
//Add a map of the spatial coverage
if (gmaps) viewRef.insertSpatialCoverageMap();

// Injects Clipboard objects into DOM elements returned from the View Service
viewRef.insertCopiables();
// Injects Clipboard objects into DOM elements returned from the View Service
viewRef.insertCopiables();

}
} catch (e) {
console.log("Error rendering metadata from the view service", e);
console.log("Response from the view service: ", response);
viewRef.renderMetadataFromIndex();
}
},
error: function (xhr, textStatus, errorThrown) {
Expand Down