Skip to content

Instantly share code, notes, and snippets.

@Prashant1293
Created July 3, 2018 09:08
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/b938e73a38cc3edf85337243aaf762cd to your computer and use it in GitHub Desktop.
Save Prashant1293/b938e73a38cc3edf85337243aaf762cd 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(Configuration 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