replace ArgumentInvalidException by ValidationBadRequest in Controllers

This commit is contained in:
ngfrolov 2023-09-28 17:50:58 +05:00
parent 4a6bc2c747
commit 33c49e8a48
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
4 changed files with 12 additions and 8 deletions

View File

@ -169,8 +169,9 @@ namespace AsbCloudWebApi.Controllers
if (!await UserHasAccesToWellAsync(idWell, token))
return Forbid();
var well = await wellService.GetOrDefaultAsync(idWell, token)
?? throw new ArgumentInvalidException($"Скважина c id:{idWell} не найдена", nameof(idWell));
var well = await wellService.GetOrDefaultAsync(idWell, token);
if (well is null)
return this.ValidationBadRequest(nameof(idWell), $"Скважина c id:{idWell} не найдена");
var stream = await dailyReportService.MakeReportAsync(idWell, date, token);
if (stream is null)

View File

@ -119,10 +119,10 @@ namespace AsbCloudWebApi.Controllers
return Forbid();
if (files.Count > 1)
throw new ArgumentInvalidException("only 1 file can be uploaded", nameof(files));
return this.ValidationBadRequest(nameof(files), "only 1 file can be uploaded");
if (files.Count == 0)
throw new ArgumentInvalidException("at list 1 file should be uploaded", nameof(files));
return this.ValidationBadRequest(nameof(files), "at list 1 file should be uploaded");
var fileName = files[0].FileName;

View File

@ -87,8 +87,9 @@ public class NotificationController : ControllerBase
public async Task<IActionResult> GetAsync([Required] int idNotification,
CancellationToken cancellationToken)
{
var notification = await notificationRepository.GetOrDefaultAsync(idNotification, cancellationToken)
?? throw new ArgumentInvalidException("Уведомление не найдено", nameof(idNotification));
var notification = await notificationRepository.GetOrDefaultAsync(idNotification, cancellationToken);
if (notification is null)
return this.ValidationBadRequest(nameof(idNotification), "Уведомление не найдено");
return Ok(notification);
}

View File

@ -64,7 +64,8 @@ namespace AsbCloudWebApi.Controllers
var result = await service.UpsertAsync((int)userId, key, value, token).ConfigureAwait(false);
if (result < 0)
throw new ArgumentInvalidException("not found", nameof(key));
return this.ValidationBadRequest(nameof(key), "not found");
return Ok(result);
}
@ -84,7 +85,8 @@ namespace AsbCloudWebApi.Controllers
var result = await service.DeleteAsync((int)userId, key, token).ConfigureAwait(false);
if (result < 0)
throw new ArgumentInvalidException("not found", nameof(key));
return this.ValidationBadRequest(nameof(key), "not found");
return Ok(result);
}