summaryrefslogtreecommitdiff
path: root/src/file/errors
diff options
context:
space:
mode:
Diffstat (limited to 'src/file/errors')
-rw-r--r--src/file/errors/not_create.cpp25
-rw-r--r--src/file/errors/not_create.hpp18
-rw-r--r--src/file/errors/registrator.cpp32
-rw-r--r--src/file/errors/registrator.hpp21
-rw-r--r--src/file/errors/types/ierror.hpp21
5 files changed, 117 insertions, 0 deletions
diff --git a/src/file/errors/not_create.cpp b/src/file/errors/not_create.cpp
new file mode 100644
index 0000000..54995ae
--- /dev/null
+++ b/src/file/errors/not_create.cpp
@@ -0,0 +1,25 @@
+#include <fstream>
+
+#include "not_create.hpp"
+#include "converter/struct_to_file.hpp"
+#include "converter/file_to_string.hpp"
+#include "logger/logger_set.hpp"
+
+namespace smtp::file::errors
+{
+ NotCreatedFile::NotCreatedFile( std::string const& path )
+ : mPath( path )
+ {
+
+ }
+
+ void NotCreatedFile::Process( types::SettingsType settings_type ) const
+ {
+ std::fstream file( mPath,std::fstream::out );
+ file.close();
+ settings_type == types::SettingsType::Server ?
+ logger::LoggerSet::GetInstance()->LogOk("Created new settings for server"):
+ logger::LoggerSet::GetInstance()->LogOk("Created new settings for recipients");
+ }
+
+}
diff --git a/src/file/errors/not_create.hpp b/src/file/errors/not_create.hpp
new file mode 100644
index 0000000..05046de
--- /dev/null
+++ b/src/file/errors/not_create.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "types/ierror.hpp"
+#include "general/struct.hpp"
+
+namespace smtp::file::errors
+{
+ class NotCreatedFile : public types::IError
+ {
+ public:
+ explicit NotCreatedFile( std::string const& path );
+ ~NotCreatedFile() override = default;
+
+ void Process( types::SettingsType settings_type ) const override;
+ private:
+ std::string mPath;
+ };
+}
diff --git a/src/file/errors/registrator.cpp b/src/file/errors/registrator.cpp
new file mode 100644
index 0000000..9389179
--- /dev/null
+++ b/src/file/errors/registrator.cpp
@@ -0,0 +1,32 @@
+#include <cerrno>
+
+#include "registrator.hpp"
+#include "logger/logger_set.hpp"
+
+namespace smtp::file::errors
+{
+
+ void Registrator::Add( types::IErrorPtr const& error, int error_code )
+ {
+ mErrorSet.insert( {error_code, error} );
+ }
+
+ void Registrator::Process( types::SettingsType settings_type ) const
+ {
+ auto find = mErrorSet.find(errno);
+ if( find == mErrorSet.end() )
+ {
+ DefaultProcess(errno);
+ }
+ find->second->Process( settings_type );
+ }
+
+ void Registrator::DefaultProcess(int error_code) const
+ {
+ static const std::string METHOD = "Open file";
+
+ std::string message = "Unknown error - " + std::to_string(error_code);
+ logger::LoggerSet::GetInstance()->LogError( METHOD, message );
+ }
+
+}
diff --git a/src/file/errors/registrator.hpp b/src/file/errors/registrator.hpp
new file mode 100644
index 0000000..381db2f
--- /dev/null
+++ b/src/file/errors/registrator.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <map>
+
+#include "types/ierror.hpp"
+
+namespace smtp::file::errors
+{
+ class Registrator
+ {
+ public:
+ Registrator() = default;
+ ~Registrator() = default;
+
+ void Add( types::IErrorPtr const& error, int error_code );
+ void Process( types::SettingsType settings_type ) const;
+ private:
+ void DefaultProcess( int error_code ) const;
+ std::map< int, types::IErrorPtr > mErrorSet;
+ };
+}
diff --git a/src/file/errors/types/ierror.hpp b/src/file/errors/types/ierror.hpp
new file mode 100644
index 0000000..6a47ddb
--- /dev/null
+++ b/src/file/errors/types/ierror.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <memory>
+
+namespace smtp::file::errors::types
+{
+ enum class SettingsType
+ {
+ Server,
+ Mail
+ };
+
+ class IError
+ {
+ public:
+ virtual ~IError() = default;
+
+ virtual void Process( SettingsType settings_type ) const = 0;
+ };
+ using IErrorPtr = std::shared_ptr<IError>;
+}