mirror of
https://github.com/Syping/dtranslatebot.git
synced 2026-04-21 14:40:41 +02:00
curl_exception: implement exception class to throw libcurl errors
This commit is contained in:
parent
ce6b3785ac
commit
8de0473669
3 changed files with 74 additions and 1 deletions
|
|
@ -18,11 +18,12 @@
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
cmake_policy(VERSION 3.16...3.27)
|
cmake_policy(VERSION 3.16...3.27)
|
||||||
project(dtranslatebot VERSION 0.3.3 LANGUAGES CXX)
|
project(dtranslatebot VERSION 0.4.0 LANGUAGES CXX)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
# dtranslatebot Source files
|
# dtranslatebot Source files
|
||||||
set(DTRANSLATEBOT_HEADERS
|
set(DTRANSLATEBOT_HEADERS
|
||||||
|
src/core/curl_exception.h
|
||||||
src/core/database.h
|
src/core/database.h
|
||||||
src/core/http_headers.h
|
src/core/http_headers.h
|
||||||
src/core/http_request.h
|
src/core/http_request.h
|
||||||
|
|
@ -43,6 +44,7 @@ set(DTRANSLATEBOT_HEADERS
|
||||||
src/translator/stub/stub.h
|
src/translator/stub/stub.h
|
||||||
)
|
)
|
||||||
set(DTRANSLATEBOT_SOURCES
|
set(DTRANSLATEBOT_SOURCES
|
||||||
|
src/core/curl_exception.cpp
|
||||||
src/core/database.cpp
|
src/core/database.cpp
|
||||||
src/core/http_headers.cpp
|
src/core/http_headers.cpp
|
||||||
src/core/http_request.cpp
|
src/core/http_request.cpp
|
||||||
|
|
|
||||||
30
src/core/curl_exception.cpp
Normal file
30
src/core/curl_exception.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* dtranslatebot Discord Translate Bot
|
||||||
|
* Copyright (C) 2026 Syping
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* This software is provided as-is, no warranties are given to you, we are not
|
||||||
|
* responsible for anything with use of the software, you are self responsible.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "curl_exception.h"
|
||||||
|
using namespace bot::exception;
|
||||||
|
|
||||||
|
curl_exception::curl_exception(const std::string &message, CURLcode error_code) : m_message(message), m_error_code(error_code) {
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_exception::~curl_exception() noexcept {
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* curl_exception::what() const noexcept {
|
||||||
|
return m_message.c_str();
|
||||||
|
}
|
||||||
41
src/core/curl_exception.h
Normal file
41
src/core/curl_exception.h
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* dtranslatebot Discord Translate Bot
|
||||||
|
* Copyright (C) 2026 Syping
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* This software is provided as-is, no warranties are given to you, we are not
|
||||||
|
* responsible for anything with use of the software, you are self responsible.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CURL_EXCEPTION_H
|
||||||
|
#define CURL_EXCEPTION_H
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace bot {
|
||||||
|
namespace exception {
|
||||||
|
class curl_exception : public std::exception {
|
||||||
|
public:
|
||||||
|
explicit curl_exception(const std::string &message, CURLcode error_code);
|
||||||
|
virtual ~curl_exception() noexcept;
|
||||||
|
const char* what() const noexcept override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::string m_message;
|
||||||
|
const CURLcode m_error_code;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CURL_EXCEPTION_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue