Exemplo n.º 1
0
 public IActionResult GetDocumentByUrl([FromBody] UrlForm data)
 {
     try
     {
         var request = WebRequest.Create(data.Url);
         request.Method = "GET";
         using (var responce = request.GetResponse())
             using (var stream = responce.GetResponseStream())
                 using (var reader = new StreamReader(stream))
                 {
                     var content = reader.ReadToEnd();
                     var d       = _generator.ConvertJsonToPdf(content);
                     var id      = _storage.SaveDocument(d);
                     return(Ok(new
                     {
                         id,
                         error = (string)null
                     }));
                 }
     }
     catch (WebException e)
     {
         return(Ok(new
         {
             id = (string)null,
             error = "WebException"
         }));
     }
     catch (DocumentGenerationException e)
     {
         return(Ok(new
         {
             id = (string)null,
             error = "GenerationError"
         }));
     }
     catch (Exception e)
     {
         _log.Error("Unknown exception", e);
         return(Ok(new
         {
             id = (string)null,
             error = "UnknownException"
         }));
     }
 }