forked from ddrilling/AsbCloudServer
replace ArgumentInvalidException by ValidationBadRequest in Controllers
This commit is contained in:
parent
4a6bc2c747
commit
33c49e8a48
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user