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

add better error messaging upon rules collection creation #109

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
17 changes: 13 additions & 4 deletions app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory,
jsonBody.map { json =>
val searchIndexName = (json \ "name").as[String]
val searchIndexDescription = (json \ "description").as[String]
val solrIndexId = searchManagementRepository.addNewSolrIndex(
SolrIndex(name = searchIndexName, description = searchIndexDescription)
)

Ok(Json.toJson(ApiResult(API_RESULT_OK, "Successfully added Deployment Channel '" + searchIndexName + "'.", Some(solrIndexId))))
try {
var solrIndexId = searchManagementRepository.addNewSolrIndex(
SolrIndex(name = searchIndexName, description = searchIndexDescription)
);
logger.debug("solrIndexId:" + solrIndexId);
Ok(Json.toJson(ApiResult(API_RESULT_OK, "Successfully added Deployment Channel '" + searchIndexName + "'.", Some(solrIndexId))))
} catch {
case e: Exception => {
logger.debug("The searchIndexDescription (Search Engine Collection Name) given was likely a duplicate.");
BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "Could not add Rules Collection. Only one Rules Collection per Search Engine Collection is allowed.", None)))
};
}

}.getOrElse {
BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "Adding new Deployment Channel failed. Unexpected body data.", None)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ export class RulesCollectionCreateComponent implements OnInit, OnChanges {
.then(() => this.showSuccessMsg.emit("Created new Rules Collection " + this.description))
.then(() => this.solrService.emitRulesCollectionChangeEvent(""))
.then(() => this.clearForm())
.catch(error => this.showErrorMsg.emit(error));
.catch(error => {
console.log(error);
var errorMsg = 'Unknown Error'
if ('message' in error.error) {
errorMsg = error.error.message;
}
this.showErrorMsg.emit(errorMsg);
});
} else {
this.showErrorMsg.emit("Fill in both name fields.");
}
}


}