better exception logging
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
package org.lucares.pdbui;
|
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
|
|
||||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason = "Internal Server Error")
|
|
||||||
public class InternalServerError extends RuntimeException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public InternalServerError(final String message, final Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InternalServerError(final Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Not Found")
|
||||||
|
public class NotFoundException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 694206253376122420L;
|
||||||
|
|
||||||
|
public NotFoundException(final String message, final Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotFoundException(final Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.lucares.ludb.FieldNotExistsException;
|
||||||
import org.lucares.ludb.Proposal;
|
import org.lucares.ludb.Proposal;
|
||||||
import org.lucares.pdb.plot.api.PlotSettings;
|
import org.lucares.pdb.plot.api.PlotSettings;
|
||||||
import org.lucares.pdbui.domain.AutocompleteProposal;
|
import org.lucares.pdbui.domain.AutocompleteProposal;
|
||||||
@@ -44,32 +45,26 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
|
||||||
)
|
)
|
||||||
@ResponseBody
|
@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());
|
final Path relativeImagePath = plotter.getOutputDir().relativize(image.toPath());
|
||||||
return new PlotResponse(WEB_IMAGE_OUTPUT_PATH + "/" + relativeImagePath.toString());
|
final String relativeImgUrl = relativeImagePath.toString().replace('\\', '/');
|
||||||
|
return new PlotResponse(WEB_IMAGE_OUTPUT_PATH + "/" + relativeImgUrl);
|
||||||
} catch (final InternalPlottingException e) {
|
|
||||||
throw new InternalServerError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(path = "/autocomplete", //
|
@RequestMapping(path = "/autocomplete", //
|
||||||
method = RequestMethod.GET, //
|
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 //
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
|
||||||
)
|
)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
AutocompleteResponse autocomplete(@RequestParam(name = "query") final String query,
|
AutocompleteResponse autocomplete(@RequestParam(name = "query") final String query,
|
||||||
@RequestParam(name = "caretIndex") final int caretIndex) {
|
@RequestParam(name = "caretIndex") final int caretIndex) {
|
||||||
|
|
||||||
try {
|
|
||||||
final AutocompleteResponse result = new AutocompleteResponse();
|
final AutocompleteResponse result = new AutocompleteResponse();
|
||||||
final int zeroBasedCaretIndex = caretIndex - 1;
|
final int zeroBasedCaretIndex = caretIndex - 1;
|
||||||
|
|
||||||
@@ -81,11 +76,6 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
|
|
||||||
result.setProposals(autocompleteProposals);
|
result.setProposals(autocompleteProposals);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} catch (final Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new InternalServerError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(path = "/fields", //
|
@RequestMapping(path = "/fields", //
|
||||||
@@ -95,16 +85,9 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
)
|
)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
List<String> fields() {
|
List<String> fields() {
|
||||||
|
|
||||||
try {
|
|
||||||
final List<String> fields = db.getDb().getFields();
|
final List<String> fields = db.getDb().getFields();
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
|
|
||||||
} catch (final Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new InternalServerError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(path = "/fields/{fieldName}/values", //
|
@RequestMapping(path = "/fields/{fieldName}/values", //
|
||||||
@@ -120,10 +103,8 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
final List<String> fields = db.getDb().getFieldsValues(query, fieldName);
|
final List<String> fields = db.getDb().getFieldsValues(query, fieldName);
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
|
} catch (final FieldNotExistsException e) {
|
||||||
} catch (final Exception e) {
|
throw new NotFoundException(e);
|
||||||
e.printStackTrace();
|
|
||||||
throw new InternalServerError(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%t] %c
|
|||||||
|
|
||||||
rootLogger.level = info
|
rootLogger.level = info
|
||||||
rootLogger.appenderRef.stdout.ref = STDOUT
|
rootLogger.appenderRef.stdout.ref = STDOUT
|
||||||
|
|
||||||
|
## log all exceptions thrown by controllers. Otherwise only 500 will be logged.
|
||||||
|
#log4j.logger.org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver=debug
|
||||||
Reference in New Issue
Block a user