From c72996ff9854aededc4ecfab92ef5d42167edd86 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 23 Jan 2020 20:51:02 +0800 Subject: ... --- Timeline/Controllers/UserController.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Timeline/Controllers/UserController.cs') diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index 65ee3a0f..5f1b7bd7 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -35,13 +35,16 @@ namespace Timeline.Controllers [HttpGet("users/{username}"), AdminAuthorize] public async Task> Get([FromRoute][Username] string username) { - var user = await _userService.GetUserByUsername(username); - if (user == null) + try + { + var user = await _userService.GetUserByUsername(username); + return Ok(user); + } + catch (UserNotExistException e) { - _logger.LogInformation(Log.Format(LogGetUserNotExist, ("Username", username))); + _logger.LogInformation(e, Log.Format(LogGetUserNotExist, ("Username", username))); return NotFound(ErrorResponse.UserCommon.NotExist()); } - return Ok(user); } [HttpPut("users/{username}"), AdminAuthorize] -- cgit v1.2.3