All operation-generated error messages should have the 400 HTTP error code. It's a real nag to have to type it every time. So make it the default. Signed-off-by: Nadav Har'El <nyh@scylladb.com>
52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
/*
|
|
* Copyright 2019 ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* This file is part of Scylla.
|
|
*
|
|
* See the LICENSE.PROPRIETARY file in the top-level directory for licensing information.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "log.hh"
|
|
#include "alternator/executor.hh"
|
|
#include <seastar/core/future.hh>
|
|
#include <seastar/http/httpd.hh>
|
|
|
|
namespace alternator {
|
|
|
|
class server {
|
|
seastar::httpd::http_server_control _control;
|
|
seastar::sharded<executor>& _executor;
|
|
public:
|
|
server(seastar::sharded<executor>& executor) : _executor(executor) {}
|
|
|
|
seastar::future<> init(uint16_t port);
|
|
private:
|
|
void set_routes(seastar::httpd::routes& r);
|
|
};
|
|
|
|
// DynamoDB's error messages are described in detail in
|
|
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html
|
|
// Ah An error message has a "type", e.g., "ResourceNotFoundException", a coarser
|
|
// HTTP code (almost always, 400), and a human readable message. Eventually these
|
|
// will be wrapped into a JSON object returned to the client.
|
|
class api_error : public std::exception {
|
|
public:
|
|
reply::status_type _http_code;
|
|
sstring _type;
|
|
sstring _msg;
|
|
api_error(sstring type, sstring msg, reply::status_type http_code = reply::status_type::bad_request)
|
|
: _http_code(std::move(http_code))
|
|
, _type(std::move(type))
|
|
, _msg(std::move(msg))
|
|
{ }
|
|
api_error() { }
|
|
virtual const char* what() const noexcept override { return _msg.begin(); }
|
|
};
|
|
|
|
}
|
|
|