0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 23:44:01 +01:00

ircd:Ⓜ️:error: Improve constructions; ensure json content-type.

This commit is contained in:
Jason Volk 2018-12-30 17:34:27 -08:00
parent af37529470
commit 6e71c05586
2 changed files with 52 additions and 13 deletions

View file

@ -33,6 +33,15 @@ class ircd::m::error
{ {
static thread_local char fmtbuf[4_KiB]; static thread_local char fmtbuf[4_KiB];
IRCD_OVERLOAD(internal)
error(internal_t, const http::code &, const json::strung &object);
protected:
IRCD_OVERLOAD(child)
template<class... args> error(child_t, args&&... a)
:error{std::forward<args>(a)...}
{}
public: public:
template<class... args> error(const http::code &, const string_view &errcode, const string_view &fmt, args&&...); template<class... args> error(const http::code &, const string_view &errcode, const string_view &fmt, args&&...);
template<class... args> error(const string_view &errcode, const string_view &fmt, args&&...); template<class... args> error(const string_view &errcode, const string_view &fmt, args&&...);
@ -42,11 +51,6 @@ class ircd::m::error
error(const http::code &); error(const http::code &);
error(std::string); error(std::string);
error(); error();
IRCD_OVERLOAD(child)
template<class... args> error(child_t, args&&... a)
:error{std::forward<args>(a)...}
{}
}; };
/// Macro for all matrix exceptions; all errors rooted from m::error /// Macro for all matrix exceptions; all errors rooted from m::error
@ -112,9 +116,9 @@ ircd::m::error::error(const http::code &status,
const string_view &errcode, const string_view &errcode,
const string_view &fmt, const string_view &fmt,
args&&... a) args&&... a)
:http::error :error
{ {
status, [&errcode, &fmt, &a...]() -> json::strung internal, status, [&errcode, &fmt, &a...]() -> json::strung
{ {
const string_view str const string_view str
{ {

View file

@ -3727,34 +3727,69 @@ ircd::m::_hook_match(const m::event &matching,
// m/error.h // m/error.h
// //
namespace ircd::m
{
const std::array<http::header, 1> _error_headers
{{
{ "Content-Type", "application/json; charset=utf-8" },
}};
}
thread_local thread_local
decltype(ircd::m::error::fmtbuf) decltype(ircd::m::error::fmtbuf)
ircd::m::error::fmtbuf ircd::m::error::fmtbuf
{}; {};
ircd::m::error::error() ircd::m::error::error()
:http::error{http::INTERNAL_SERVER_ERROR} :http::error
{
http::INTERNAL_SERVER_ERROR
}
{} {}
ircd::m::error::error(std::string c) ircd::m::error::error(std::string c)
:http::error{http::INTERNAL_SERVER_ERROR, std::move(c)} :http::error
{
http::INTERNAL_SERVER_ERROR, std::move(c)
}
{} {}
ircd::m::error::error(const http::code &c) ircd::m::error::error(const http::code &c)
:http::error{c, std::string{}} :http::error
{
c, std::string{}
}
{} {}
ircd::m::error::error(const http::code &c, ircd::m::error::error(const http::code &c,
const json::members &members) const json::members &members)
:http::error{c, json::strung{members}} :error
{
internal, c, json::strung{members}
}
{} {}
ircd::m::error::error(const http::code &c, ircd::m::error::error(const http::code &c,
const json::iov &iov) const json::iov &iov)
:http::error{c, json::strung{iov}} :error
{
internal, c, json::strung{iov}
}
{} {}
ircd::m::error::error(const http::code &c, ircd::m::error::error(const http::code &c,
const json::object &object) const json::object &object)
:http::error{c, std::string{object}} :http::error
{
c, std::string{object}, vector_view<const http::header>{_error_headers}
}
{}
ircd::m::error::error(internal_t,
const http::code &c,
const json::strung &object)
:http::error
{
c, object, vector_view<const http::header>{_error_headers}
}
{} {}