public IActionResult TranslateToMorse(MorseRequest request)
        {
            return(ExecuteResponse(() =>
            {
                MorseResponse morseResponse = new MorseResponse();

                morseResponse.Response = MorseDecoder.traslate2Morse(request.Text);
                morseResponse.Code = StatusCodes.Status200OK;

                return morseResponse;
            }));
        }
示例#2
0
        public IActionResult ExecuteResponse(Func <MorseResponse> func)
        {
            try
            {
                MorseResponse responseApi = func.Invoke();
                return(StatusCode(responseApi.Code, responseApi));
            }
            catch (Exception ex)
            {
                //La ex puede ser logueada

                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  new MorseResponse()
                {
                    Code = StatusCodes.Status500InternalServerError,
                    Response = "Unespected Error"
                }));
            }
        }