public override Task <ProcessarCodeResponse> ProcessarCode(ProcessarCodeRequest request, ServerCallContext context)
        {
            var response = new ProcessarCodeResponse();

            try
            {
                var usuarioId = Guid.Parse(request.UsuarioId);
                var empresaId = Guid.Parse(request.EmpresaId);

                servico.ProcessarCode(request.Code, usuarioId, empresaId);

                response.HttpStatusCode = (int)HttpStatusCode.OK;
            }
            catch (ArgumentNullException)
            {
                response.HttpStatusCode = (int)HttpStatusCode.BadRequest;
            }
            catch (UnauthorizedAccessException)
            {
                response.HttpStatusCode = (int)HttpStatusCode.Unauthorized;
            }
            catch (InvalidCredentialException)
            {
                response.HttpStatusCode = (int)HttpStatusCode.BadRequest;
            }
            catch (Exception ex)
            {
                response.HttpStatusCode = (int)HttpStatusCode.InternalServerError;
                response.Erro           = ex.Message;
            }

            return(Task.FromResult(response));
        }
Ejemplo n.º 2
0
        public ResponseEnvelope Response(ProcessarCodeResponse response)
        {
            var envelope = new ResponseEnvelope
            {
                HttpStatusCode = (HttpStatusCode)response.HttpStatusCode
            };

            if (!envelope.Success)
            {
                envelope.Error = new ErrorEnvelope
                {
                    Exception = new Exception(response.Erro),
                    Messages  = new List <string> {
                        response.Erro
                    }
                };
            }

            return(envelope);
        }