diff options
author | claiff <claiff@mail.ru> | 2022-10-06 12:26:56 +0300 |
---|---|---|
committer | claiff <claiff@mail.ru> | 2022-10-06 12:26:56 +0300 |
commit | 04e97b30880c1c3252fe900ccac268267539e424 (patch) | |
tree | 1f4cd2d1e2f8cf2442d055c519d06c6e0692febc /src/file/errors | |
parent | 8edef99a5b52643e0b919c424357752cbbc9a8dd (diff) | |
parent | da5f91a0ce15351a82beb061c3ccc965164529bc (diff) | |
download | obmc-sila-smtp-04e97b30880c1c3252fe900ccac268267539e424.tar.xz |
Merge branch 'bugfix/proxy_file_reader'
Diffstat (limited to 'src/file/errors')
-rw-r--r-- | src/file/errors/not_create.cpp | 25 | ||||
-rw-r--r-- | src/file/errors/not_create.hpp | 18 | ||||
-rw-r--r-- | src/file/errors/registrator.cpp | 32 | ||||
-rw-r--r-- | src/file/errors/registrator.hpp | 21 | ||||
-rw-r--r-- | src/file/errors/types/ierror.hpp | 21 |
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>; +} |