add unsupportedMediaTypeException
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <cocoatweet/api/media/upload.h>
|
||||
#include <cocoatweet/api/model/mediaStore.h>
|
||||
#include <cocoatweet/exception/unsupportedMediaTypeException.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
@@ -21,6 +22,12 @@ void Upload::mediaId(const std::string& _mediaId) {}
|
||||
|
||||
CocoaTweet::API::Model::MediaStore Upload::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
auto extension = std::filesystem::path(media_).extension().string<char>();
|
||||
if (mimeType.count(extension) == 0) {
|
||||
throw new CocoaTweet::Exception::UnsupportedMediaTypeException(
|
||||
std::string("media type \"" + extension + "\" is not supported media type"));
|
||||
}
|
||||
|
||||
auto backup = bodyParam_;
|
||||
CocoaTweet::API::Model::MediaStore media;
|
||||
std::ifstream ifs(media_, std::ios::binary);
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
#include <cocoatweet/api/model/mediaStore.h>
|
||||
#include <cocoatweet/exception/tweetNotFoundException.h>
|
||||
#include <cocoatweet/exception/authenticateException.h>
|
||||
#include <cocoatweet/exception/tweetDuplicateException.h>
|
||||
#include <cocoatweet/exception/tweetTooLongException.h>
|
||||
#include <cocoatweet/exception/rateLimitException.h>
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace CocoaTweet::API::Model {
|
||||
@@ -31,6 +27,7 @@ MediaStore MediaStore::parse(const unsigned int _responseCode, const std::string
|
||||
media.remain(j["processing_info"]["check_after_secs"].get<unsigned int>());
|
||||
}
|
||||
} else {
|
||||
throw new CocoaTweet::Exception::Exception(j["error"]);
|
||||
}
|
||||
|
||||
return media;
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace CocoaTweet::Exception {
|
||||
class Exception : public std::exception {
|
||||
public:
|
||||
Exception(const char* _msg) : msg_(std::string(_msg)) {}
|
||||
Exception(const std::string& _msg) : msg_(std::string(_msg)) {}
|
||||
const std::string& what() {
|
||||
return msg_;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef COCOATWEET_EXCEPTION_UNSUPPORTEDMEDIATYPEEXCEPTION_H_
|
||||
#define COCOATWEET_EXCEPTION_UNSUPPORTEDMEDIATYPEEXCEPTION_H_
|
||||
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
|
||||
namespace CocoaTweet::Exception {
|
||||
class UnsupportedMediaTypeException final : Exception {
|
||||
using Exception::Exception;
|
||||
};
|
||||
} // namespace CocoaTweet::Exception
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user