pixwhile/routes/users/users.cpp

28 lines
1.0 KiB
C++
Raw Normal View History

2023-04-05 16:36:20 +00:00
#include "../routes.h"
#include "../../numberhelper.h"
2023-04-05 16:36:20 +00:00
#include "../../servehelper.h"
#include "../../pixivclient.h"
#include "common.h"
void users_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) {
uint64_t user_id = to_ull(req.matches[1].str());
User user;
try {
user = pixiv_client.get_user(user_id);
} catch (const PixivException& e) {
if (e.status == 404) {
res.status = 404;
serve_error(req, res, config, "404: User not found", e.what());
} else {
res.status = 500;
serve_error(req, res, config, "500: Internal server error", "Failed to fetch user information", e.what());
}
return;
} catch (const std::exception& e) {
res.status = 500;
serve_error(req, res, config, "500: Internal server error", "Failed to fetch user information", e.what());
return;
}
serve(req, res, config, user.display_name + " (@" + user.username + ')', generate_user_header(user, config));
}