A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
status.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5
18#ifndef A11_STATUS_H_
19#define A11_STATUS_H_
20
21#include <cstdint>
22#include <string>
23#include <string_view>
24
25#include <absl/status/status.h>
26#include <absl/status/statusor.h>
27#include <nlohmann/json_fwd.hpp>
28
29namespace a11 {
30
37absl::StatusCode StatusCodeFromHttp(int http_code);
43int StatusCodeToHttp(absl::StatusCode code);
50absl::StatusCode StatusCodeFromWebSocket(std::uint16_t close_code);
56std::uint16_t StatusCodeToWebSocket(absl::StatusCode code);
57
69absl::Status MakeStatus(absl::StatusCode code, std::string message,
70 nlohmann::json details);
76nlohmann::json StatusDetails(const absl::Status& status);
77
83absl::StatusOr<nlohmann::json> StatusToJson(const absl::Status& status);
90absl::StatusOr<absl::Status> StatusFromJson(const nlohmann::json& value);
91
93constexpr std::string_view kStatusDetailsPayloadUrl =
94 "type.a11.dev/status-details+json";
95
96} // namespace a11
97
98#endif // A11_STATUS_H_
Definition action.cc:46
std::uint16_t StatusCodeToWebSocket(absl::StatusCode code)
Maps a canonical status code to its WebSocket close code.
Definition status.cc:146
absl::StatusCode StatusCodeFromWebSocket(std::uint16_t close_code)
Maps a WebSocket close code to a canonical status code.
Definition status.cc:91
nlohmann::json StatusDetails(const absl::Status &status)
Extracts the structured-details payload from a status.
Definition status.cc:171
constexpr std::string_view kStatusDetailsPayloadUrl
Type URL identifying A11's status-details payload.
Definition status.h:93
absl::StatusOr< nlohmann::json > StatusToJson(const absl::Status &status)
Serializes a status (code, message, details) to JSON.
Definition status.cc:186
absl::Status MakeStatus(absl::StatusCode code, std::string message, nlohmann::json details)
Builds a status carrying an A11 structured-details payload.
Definition status.cc:157
absl::StatusCode StatusCodeFromHttp(int http_code)
Maps an HTTP status code to a canonical status code.
Definition status.cc:23
int StatusCodeToHttp(absl::StatusCode code)
Maps a canonical status code to its HTTP status code.
Definition status.cc:55
absl::StatusOr< absl::Status > StatusFromJson(const nlohmann::json &value)
Reconstructs a status from its JSON representation.
Definition status.cc:197
Future< T > SubmitWithCancellationHook(absl::AnyInvocable< absl::StatusOr< T >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
Run work on A11's fiber pool with application-specific cancellation.
Definition executor.h:30