Skip to content

Instantly share code, notes, and snippets.

@Prashant1293
Created July 3, 2018 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prashant1293/78eb08a2e927db2d62fcf53b10f23cef to your computer and use it in GitHub Desktop.
Save Prashant1293/78eb08a2e927db2d62fcf53b10f23cef to your computer and use it in GitHub Desktop.
@Singleton
public class ErrorHandler extends DefaultHttpErrorHandler {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@Inject
public ErrorHandler(Config configuration, Environment environment,
OptionalSourceMapper sourceMapper, Provider<Router> routes) {
super(configuration, environment, sourceMapper, routes);
}
@Override
protected CompletionStage<Result> onNotFound(Http.RequestHeader request, String message) {
String errorResponse = "The requested resource does not exist.";
JsonNode jsonNode = OBJECT_MAPPER.valueToTree(errorResponse);
return CompletableFuture.completedFuture(Results.notFound(jsonNode));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment