Remove exception handler

This commit is contained in:
crobibero 2020-04-21 07:55:01 -06:00
parent 440f060da6
commit 5ef71d592b

View file

@ -53,16 +53,9 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult GetDevices([FromQuery] bool? supportsSync, [FromQuery] Guid? userId) public IActionResult GetDevices([FromQuery] bool? supportsSync, [FromQuery] Guid? userId)
{ {
try var deviceQuery = new DeviceQuery { SupportsSync = supportsSync, UserId = userId ?? Guid.Empty };
{ var devices = _deviceManager.GetDevices(deviceQuery);
var deviceQuery = new DeviceQuery { SupportsSync = supportsSync, UserId = userId ?? Guid.Empty }; return Ok(devices);
var devices = _deviceManager.GetDevices(deviceQuery);
return Ok(devices);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -77,20 +70,13 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult GetDeviceInfo([FromQuery, BindRequired] string id) public IActionResult GetDeviceInfo([FromQuery, BindRequired] string id)
{ {
try var deviceInfo = _deviceManager.GetDevice(id);
if (deviceInfo == null)
{ {
var deviceInfo = _deviceManager.GetDevice(id); return NotFound();
if (deviceInfo == null) }
{
return NotFound();
}
return Ok(deviceInfo); return Ok(deviceInfo);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -105,20 +91,13 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult GetDeviceOptions([FromQuery, BindRequired] string id) public IActionResult GetDeviceOptions([FromQuery, BindRequired] string id)
{ {
try var deviceInfo = _deviceManager.GetDeviceOptions(id);
if (deviceInfo == null)
{ {
var deviceInfo = _deviceManager.GetDeviceOptions(id); return NotFound();
if (deviceInfo == null) }
{
return NotFound();
}
return Ok(deviceInfo); return Ok(deviceInfo);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -136,21 +115,14 @@ namespace Jellyfin.Api.Controllers
[FromQuery, BindRequired] string id, [FromQuery, BindRequired] string id,
[FromBody, BindRequired] DeviceOptions deviceOptions) [FromBody, BindRequired] DeviceOptions deviceOptions)
{ {
try var existingDeviceOptions = _deviceManager.GetDeviceOptions(id);
if (existingDeviceOptions == null)
{ {
var existingDeviceOptions = _deviceManager.GetDeviceOptions(id); return NotFound();
if (existingDeviceOptions == null) }
{
return NotFound();
}
_deviceManager.UpdateDeviceOptions(id, deviceOptions); _deviceManager.UpdateDeviceOptions(id, deviceOptions);
return Ok(); return Ok();
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -163,21 +135,14 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult DeleteDevice([FromQuery, BindRequired] string id) public IActionResult DeleteDevice([FromQuery, BindRequired] string id)
{ {
try var sessions = _authenticationRepository.Get(new AuthenticationInfoQuery { DeviceId = id }).Items;
{
var sessions = _authenticationRepository.Get(new AuthenticationInfoQuery { DeviceId = id }).Items;
foreach (var session in sessions) foreach (var session in sessions)
{
_sessionManager.Logout(session);
}
return Ok();
}
catch (Exception e)
{ {
return StatusCode(StatusCodes.Status500InternalServerError, e.Message); _sessionManager.Logout(session);
} }
return Ok();
} }
/// <summary> /// <summary>
@ -190,15 +155,8 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult GetCameraUploads([FromQuery, BindRequired] string id) public IActionResult GetCameraUploads([FromQuery, BindRequired] string id)
{ {
try var uploadHistory = _deviceManager.GetCameraUploadHistory(id);
{ return Ok(uploadHistory);
var uploadHistory = _deviceManager.GetCameraUploadHistory(id);
return Ok(uploadHistory);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -219,46 +177,33 @@ namespace Jellyfin.Api.Controllers
[FromQuery, BindRequired] string name, [FromQuery, BindRequired] string name,
[FromQuery, BindRequired] string id) [FromQuery, BindRequired] string id)
{ {
try Stream fileStream;
{ string contentType;
Stream fileStream;
string contentType;
if (Request.HasFormContentType) if (Request.HasFormContentType)
{
if (Request.Form.Files.Any())
{ {
if (Request.Form.Files.Any()) fileStream = Request.Form.Files[0].OpenReadStream();
{ contentType = Request.Form.Files[0].ContentType;
fileStream = Request.Form.Files[0].OpenReadStream();
contentType = Request.Form.Files[0].ContentType;
}
else
{
return BadRequest();
}
} }
else else
{ {
fileStream = Request.Body; return BadRequest();
contentType = Request.ContentType;
} }
await _deviceManager.AcceptCameraUpload(
deviceId,
fileStream,
new LocalFileInfo
{
MimeType = contentType,
Album = album,
Name = name,
Id = id
}).ConfigureAwait(false);
return Ok();
} }
catch (Exception e) else
{ {
return StatusCode(StatusCodes.Status500InternalServerError, e.Message); fileStream = Request.Body;
contentType = Request.ContentType;
} }
await _deviceManager.AcceptCameraUpload(
deviceId,
fileStream,
new LocalFileInfo { MimeType = contentType, Album = album, Name = name, Id = id }).ConfigureAwait(false);
return Ok();
} }
} }
} }