better exception logging
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.lucares.ludb.FieldNotExistsException;
|
||||
import org.lucares.ludb.Proposal;
|
||||
import org.lucares.pdb.plot.api.PlotSettings;
|
||||
import org.lucares.pdbui.domain.AutocompleteProposal;
|
||||
@@ -44,48 +45,37 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
|
||||
)
|
||||
@ResponseBody
|
||||
PlotResponse createPlot(@RequestBody final PlotRequest request) {
|
||||
PlotResponse createPlot(@RequestBody final PlotRequest request) throws InternalPlottingException {
|
||||
|
||||
try {
|
||||
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
||||
|
||||
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
|
||||
final File image = plotter.plot(plotSettings);
|
||||
|
||||
final File image = plotter.plot(plotSettings);
|
||||
|
||||
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
||||
return new PlotResponse(WEB_IMAGE_OUTPUT_PATH + "/" + relativeImagePath.toString());
|
||||
|
||||
} catch (final InternalPlottingException e) {
|
||||
throw new InternalServerError(e);
|
||||
}
|
||||
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
||||
final String relativeImgUrl = relativeImagePath.toString().replace('\\', '/');
|
||||
return new PlotResponse(WEB_IMAGE_OUTPUT_PATH + "/" + relativeImgUrl);
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/autocomplete", //
|
||||
method = RequestMethod.GET, //
|
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, // APPLICATION_JSON_UTF8_VALUE
|
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, //
|
||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
|
||||
)
|
||||
@ResponseBody
|
||||
AutocompleteResponse autocomplete(@RequestParam(name = "query") final String query,
|
||||
@RequestParam(name = "caretIndex") final int caretIndex) {
|
||||
|
||||
try {
|
||||
final AutocompleteResponse result = new AutocompleteResponse();
|
||||
final int zeroBasedCaretIndex = caretIndex - 1;
|
||||
final AutocompleteResponse result = new AutocompleteResponse();
|
||||
final int zeroBasedCaretIndex = caretIndex - 1;
|
||||
|
||||
final List<Proposal> proposals = db.autocomplete(query, zeroBasedCaretIndex);
|
||||
final List<Proposal> nonEmptyProposals = filter(proposals, p -> p.getResults() > 0);
|
||||
final List<Proposal> proposals = db.autocomplete(query, zeroBasedCaretIndex);
|
||||
final List<Proposal> nonEmptyProposals = filter(proposals, p -> p.getResults() > 0);
|
||||
|
||||
final List<AutocompleteProposal> autocompleteProposals = toAutocompleteProposals(nonEmptyProposals);
|
||||
Collections.sort(autocompleteProposals, new AutocompleteProposalByValue());
|
||||
final List<AutocompleteProposal> autocompleteProposals = toAutocompleteProposals(nonEmptyProposals);
|
||||
Collections.sort(autocompleteProposals, new AutocompleteProposalByValue());
|
||||
|
||||
result.setProposals(autocompleteProposals);
|
||||
return result;
|
||||
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new InternalServerError(e);
|
||||
}
|
||||
result.setProposals(autocompleteProposals);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/fields", //
|
||||
@@ -95,16 +85,9 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
)
|
||||
@ResponseBody
|
||||
List<String> fields() {
|
||||
final List<String> fields = db.getDb().getFields();
|
||||
|
||||
try {
|
||||
final List<String> fields = db.getDb().getFields();
|
||||
|
||||
return fields;
|
||||
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new InternalServerError(e);
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/fields/{fieldName}/values", //
|
||||
@@ -120,10 +103,8 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
final List<String> fields = db.getDb().getFieldsValues(query, fieldName);
|
||||
|
||||
return fields;
|
||||
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new InternalServerError(e);
|
||||
} catch (final FieldNotExistsException e) {
|
||||
throw new NotFoundException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user