|
@@ -62,23 +62,38 @@ public class VideosController {
|
|
|
|
|
|
@GetMapping("{id}")
|
|
|
public ResponseEntity<?> findVideoById(@PathVariable("id") String id){
|
|
|
- Video v = template.getForObject(videosApi+"/"+id, Video.class);
|
|
|
- if(v.getId() != null) {
|
|
|
- return new ResponseEntity<Video>(v, HttpStatus.OK);
|
|
|
+ try {
|
|
|
+ Video v = template.getForObject(videosApi+"/"+id, Video.class);
|
|
|
+ if(v.getId() != null) {
|
|
|
+ return new ResponseEntity<Video>(v, HttpStatus.OK);
|
|
|
+ }
|
|
|
+ return new ResponseEntity<String>("Video not found", HttpStatus.NOT_FOUND);
|
|
|
}
|
|
|
- return new ResponseEntity<String>("Video not found", HttpStatus.NOT_FOUND);
|
|
|
+ catch(ResourceAccessException e){ }
|
|
|
+
|
|
|
+ return new ResponseEntity<String>("Cannot connect to repository", HttpStatus.SERVICE_UNAVAILABLE);
|
|
|
}
|
|
|
|
|
|
@PostMapping()
|
|
|
public ResponseEntity<?> createVideo(@RequestBody Video video) {
|
|
|
- ResponseEntity<Video> response = template.postForEntity(videosApi, video, Video.class);
|
|
|
- return response;
|
|
|
+ try {
|
|
|
+ ResponseEntity<Video> response = template.postForEntity(videosApi, video, Video.class);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ catch(ResourceAccessException e){ }
|
|
|
+
|
|
|
+ return new ResponseEntity<String>("Cannot connect to repository", HttpStatus.SERVICE_UNAVAILABLE);
|
|
|
}
|
|
|
|
|
|
@DeleteMapping("{id}")
|
|
|
public ResponseEntity<String> deleteVideoById(@PathVariable("id") String id) {
|
|
|
- template.delete(videosApi+"/"+id);
|
|
|
- return new ResponseEntity<String>("Video deleted", HttpStatus.OK);
|
|
|
+ try {
|
|
|
+ template.delete(videosApi+"/"+id);
|
|
|
+ return new ResponseEntity<String>("Video deleted", HttpStatus.OK);
|
|
|
+ }
|
|
|
+ catch(ResourceAccessException e){ }
|
|
|
+
|
|
|
+ return new ResponseEntity<String>("Cannot connect to repository", HttpStatus.SERVICE_UNAVAILABLE);
|
|
|
}
|
|
|
|
|
|
|