SES-129 Add errorReponse
This commit is contained in:
parent
12a30784e1
commit
146abad9f5
@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SessionCompanion.Extensions.EitherType;
|
||||
using SessionCompanion.Services.Interfaces;
|
||||
using SessionCompanion.ViewModels.ApiResponses;
|
||||
using SessionCompanion.ViewModels.SpellViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -20,9 +22,21 @@ namespace SessionCompanion.Controllers
|
||||
/// </summary>
|
||||
/// <returns>Lista wszystkich zaklęć w bazie danych</returns>
|
||||
[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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user