From 146abad9f50703906dbc9c4e98f613722c6113c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Fri, 8 Jan 2021 17:42:57 +0100 Subject: [PATCH] SES-129 Add errorReponse --- .../Controllers/SpellController.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SessionCompanion/SessionCompanion/Controllers/SpellController.cs b/SessionCompanion/SessionCompanion/Controllers/SpellController.cs index f7696be..5ddc879 100644 --- a/SessionCompanion/SessionCompanion/Controllers/SpellController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/SpellController.cs @@ -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 /// /// Lista wszystkich zaklęć w bazie danych [HttpGet("getAllSpells")] - public async Task> GetSpells() + public async Task, 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 + }; + } } } }