SES-129 Add errorReponse

This commit is contained in:
Karol Górzyński 2021-01-08 17:42:57 +01:00
parent 12a30784e1
commit 146abad9f5

View File

@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces; using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.SpellViewModels; using SessionCompanion.ViewModels.SpellViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -20,9 +22,21 @@ namespace SessionCompanion.Controllers
/// </summary> /// </summary>
/// <returns>Lista wszystkich zaklęć w bazie danych</returns> /// <returns>Lista wszystkich zaklęć w bazie danych</returns>
[HttpGet("getAllSpells")] [HttpGet("getAllSpells")]
public async Task<List<SpellViewModel>> GetSpells() public async Task<Either<List<SpellViewModel>, ErrorResponse>> GetSpells()
{ {
return _service.Get().ToList(); try
{
var spells = _service.Get().ToList();
return spells;
}
catch (Exception e)
{
return new ErrorResponse()
{
StatusCode = 204,
Message = e.Message
};
}
} }
} }
} }