diff options
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java index b46d4ee..82b2c67 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java @@ -2,6 +2,8 @@ package com.ufund.api.ufundapi.controller; import java.io.IOException; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -17,6 +19,7 @@ import com.ufund.api.ufundapi.service.AuthService; @RestController @RequestMapping("auth") public class AuthController { + private static final Logger LOG = Logger.getLogger(AuthController.class.getName()); private final AuthService authService; public AuthController(AuthService authService) { @@ -32,15 +35,18 @@ public class AuthController { */ @PostMapping("") public ResponseEntity<String> login(@RequestBody Map<String, String> params) { + LOG.log(Level.INFO, "POST /auth body={0}", params); String username = params.get("username"); String password = params.get("password"); try { String key = authService.login(username, password); return new ResponseEntity<>(key, HttpStatus.OK); - } catch (IllegalAccessException e) { - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } catch (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -52,11 +58,13 @@ public class AuthController { */ @DeleteMapping("") public ResponseEntity<Object> logout(@RequestHeader("jelly-api-key") String key) { + LOG.log(Level.INFO, "DELETE /auth key={0}", key); try { authService.logout(key); return new ResponseEntity<>(HttpStatus.OK); - } catch (IOException e) { - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } catch (IOException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } } |