Add exceptions to return 400 on save endpoint
This commit is contained in:
parent
04d46b23cc
commit
54c572a83b
2 changed files with 13 additions and 8 deletions
|
|
@ -68,10 +68,17 @@ public class KoreaderController : BaseApiController
|
|||
[HttpPut("{apiKey}/syncs/progress")]
|
||||
public async Task<ActionResult<KoreaderProgressUpdateDto>> UpdateProgress(string apiKey, KoreaderBookDto request)
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
await _koreaderService.SaveProgress(request, userId);
|
||||
try
|
||||
{
|
||||
var userId = await GetUserId(apiKey);
|
||||
await _koreaderService.SaveProgress(request, userId);
|
||||
|
||||
return Ok(new KoreaderProgressUpdateDto{ Document = request.Document, Timestamp = DateTime.UtcNow });
|
||||
return Ok(new KoreaderProgressUpdateDto{ Document = request.Document, Timestamp = DateTime.UtcNow });
|
||||
}
|
||||
catch (KavitaException ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -90,8 +97,6 @@ public class KoreaderController : BaseApiController
|
|||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
private async Task<int> GetUserId(string apiKey)
|
||||
|
|
|
|||
|
|
@ -41,16 +41,16 @@ public class KoreaderService : IKoreaderService
|
|||
{
|
||||
_logger.LogDebug("Saving Koreader progress for {UserId}: {KoreaderProgress}", userId, koreaderBookDto.Progress);
|
||||
var file = await _unitOfWork.MangaFileRepository.GetByKoreaderHash(koreaderBookDto.Document);
|
||||
if (file == null) return;
|
||||
if (file == null) throw new KavitaException(await _localizationService.Translate(userId, "file-missing"));
|
||||
|
||||
var userProgressDto = await _unitOfWork.AppUserProgressRepository.GetUserProgressDtoAsync(file.ChapterId, userId);
|
||||
if (userProgressDto == null)
|
||||
{
|
||||
var chapterDto = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(file.ChapterId);
|
||||
if (chapterDto == null) return;
|
||||
if (chapterDto == null) throw new KavitaException(await _localizationService.Translate(userId, "chapter-doesnt-exist"));
|
||||
|
||||
var volumeDto = await _unitOfWork.VolumeRepository.GetVolumeByIdAsync(chapterDto.VolumeId);
|
||||
if (volumeDto == null) return;
|
||||
if (volumeDto == null) throw new KavitaException(await _localizationService.Translate(userId, "volume-doesnt-exist"));
|
||||
|
||||
userProgressDto = new ProgressDto()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue