public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { var type = typeof(TRequest).Name; try { return(await next()); } catch (SheaftException sheaftException) { _logger.LogError(sheaftException, $"Sheaft error on executing {type} : {sheaftException.Message}"); throw; } catch (DbUpdateConcurrencyException dbUpdateConcurrency) { _logger.LogError(dbUpdateConcurrency, $"DbConcurrency error on executing {type} : {dbUpdateConcurrency.Message}"); throw SheaftException.Conflict(dbUpdateConcurrency); } catch (DbUpdateException dbUpdate) { _logger.LogError(dbUpdate, $"DbUpdate error on executing {type} : {dbUpdate.Message}"); if (dbUpdate.InnerException != null && dbUpdate.InnerException.Message.Contains("duplicate key row")) { throw SheaftException.AlreadyExists(dbUpdate); } throw SheaftException.BadRequest(dbUpdate); } catch (NotSupportedException notSupported) { _logger.LogError(notSupported, $"Not supported error on executing {type} : {notSupported.Message}"); throw SheaftException.Unexpected(notSupported); } catch (InvalidOperationException invalidOperation) { if (invalidOperation.Source == "Microsoft.EntityFrameworkCore" && invalidOperation.Message.StartsWith("Enumerator failed to MoveNextAsync")) { _logger.LogWarning(invalidOperation, $"Entity not found while processing {type}"); throw SheaftException.NotFound(invalidOperation); } _logger.LogError(invalidOperation, $"Invalid operation error on executing {type} : {invalidOperation.Message}"); throw SheaftException.Unexpected(invalidOperation); } catch (Exception e) { _logger.LogError(e, $"Unexpected error on executing {type} : {e.Message}"); throw SheaftException.Unexpected(e); } }
public ConsumerLegal SetLegals(Owner owner) { if (Legal?.Id != null) { throw SheaftException.AlreadyExists("Les informations légales de cet utilisateur existent déjà."); } var legals = new ConsumerLegal(Guid.NewGuid(), this, owner); Legal = legals; return(legals); }
public void AddSetting(Setting setting, string value) { if (Settings == null) { Settings = new List <UserSetting>(); } if (Settings.Any(s => s.Setting.Kind == setting.Kind)) { throw SheaftException.AlreadyExists("Le paramètre existe déjà."); } Settings.Add(new UserSetting(setting, value)); SettingsCount = Settings?.Count ?? 0; }
public BusinessLegal SetLegals(LegalKind kind, string name, string email, string siret, string vatIdentifier, LegalAddress address, BillingAddress billingAddress, Owner owner, string registrationCity = null, string registrationCode = null, RegistrationKind?registrationKind = null) { if (Legal?.Id != null) { throw SheaftException.AlreadyExists("Les informations légales de cette société existent déjà."); } var legals = new BusinessLegal(Guid.NewGuid(), this, kind, name, email, siret, vatIdentifier, address, owner, billingAddress); if (registrationKind.HasValue) { legals.SetRegistrationKind(registrationKind.Value, registrationCity, registrationCode); } Legal = legals; return(legals); }