/// <exception cref="UnAuthorizedProjectException">Thrown when the project is not valid or active</exception> /// <exception cref="UnableToAddExceptionizerMessageException">Thrown when we have been unable to fully persist the exception message</exception> public void Add(ExceptionizerMessage message) { try { authorizationService.AuthorizeProject(Guid.Parse(message.ApiKey)); var messageDto = Mapper.Map<ExceptionizerMessageDto>(message); exceptionRepository.Add(messageDto); } catch (UnAuthorizedProjectException exception) { //Already logged throw; } catch (UnableToPersistToMongoDbException exception) { logger.Log(ExceptionType.ExceptionizerApi, "ExceptionService: Add", exception); throw new UnableToAddExceptionizerMessageException("Cannot add message to mongodb", exception); } catch (UnableToPersistToElasticSearchException exception) { logger.Log(ExceptionType.ExceptionizerApi, "ExceptionService: Add", exception); throw new UnableToAddExceptionizerMessageException("Cannot add message to elasticsearch", exception); } catch (Exception exception) { logger.Log(ExceptionType.Unhandled, "ExceptionService: Add", exception); throw new UnableToAddExceptionizerMessageException("UNHANDLED EXCEPTION!", exception); } }
// For testing purposes only public ExceptionizerMessage Get(string productid) { var exception = new ExceptionizerMessage(); exception.ApiKey = "a6584184-14a6-4ddf-a652-0c86ac1d16e0"; exception.ClientSource = new ClientSource { Name = "local", Url = "http://ryantomlinson.com", Version = "0.1" }; exception.Environment = new Environment { OperatingSystem = "windows", Url = "http://exceptionizer.com", ProductVersion = "1.0.0", SourceEnvironment = "production" }; exception.UserInformation = new UserInformation { UserEmail = "*****@*****.**", UserId = "1235", UserName = "******" }; exception.Exceptions = new List<ExceptionizerException>() { new ExceptionizerException() { Message = "something gone wrong like", StackTrace = "this be the stacktracez", Type = "this be the type" } }; try { exceptionService.Add(exception); } catch (Exception) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An error occured trying to process your request. Please contact us for details [email protected]"), ReasonPhrase = "Critical Exception" }); } return exception; }
// PUT api/exception/5 public void Put(ExceptionizerMessage message) { try { exceptionService.Add(message); } catch (Exception) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An error occured trying to process your request. Please contact us for details [email protected]"), ReasonPhrase = "Critical Exception" }); } }
// POST api/exception public void Post(ExceptionizerMessage message) { }