SES-130 Add Error Reponse
This commit is contained in:
parent
0c29cb0554
commit
ab0aae1cdb
@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SessionCompanion.Extensions.EitherType;
|
||||
using SessionCompanion.Services.Interfaces;
|
||||
using SessionCompanion.ViewModels.ApiResponses;
|
||||
using SessionCompanion.ViewModels.ArmorViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -20,9 +22,21 @@ namespace SessionCompanion.Controllers
|
||||
/// </summary>
|
||||
/// <returns>Lista wszystkich pancerzy w bazie danych</returns>
|
||||
[HttpGet("getAllArmor")]
|
||||
public async Task<List<ArmorViewModel>> GetArmors()
|
||||
public async Task<Either<List<ArmorViewModel>, ErrorResponse>> GetArmors()
|
||||
{
|
||||
return _service.Get().ToList();
|
||||
try
|
||||
{
|
||||
var armors = _service.Get().ToList();
|
||||
return armors;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ErrorResponse()
|
||||
{
|
||||
StatusCode = 204,
|
||||
Message = e.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user