Last active
November 12, 2018 17:51
-
-
Save kshep92/f417fcdd9b329d78051a15d0a86eb24d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ControllerAdvice | |
public class NotFoundHandler { | |
@Value("${spa.default-file}") | |
String defaultFile; | |
@ExceptionHandler(NoHandlerFoundException.class) | |
public ResponseEntity<String> renderDefaultPage() { | |
try { | |
File indexFile = ResourceUtils.getFile(defaultFile); | |
FileInputStream inputStream = new FileInputStream(indexFile); | |
String body = StreamUtils.copyToString(inputStream, Charset.defaultCharset()); | |
return ResponseEntity.ok().contentType(MediaType.TEXT_HTML).body(body); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There was an error completing the action."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment