1use std::borrow::Cow;
2
3use http::StatusCode;
4
5use crate::option_ext::StatusError;
6
7macro_rules! impl_fn {
8 ($name:ident, $status:ident) => {
9 pub fn $name(context: impl Into<Cow<'static, str>>) -> StatusError {
10 StatusError::new(StatusCode::$status, context)
11 }
12 };
13}
14
15impl_fn!(bad_request, BAD_REQUEST);
16impl_fn!(unauthorized, UNAUTHORIZED);
17impl_fn!(payment_required, PAYMENT_REQUIRED);
18impl_fn!(forbidden, FORBIDDEN);
19impl_fn!(not_found, NOT_FOUND);
20impl_fn!(method_not_allowed, METHOD_NOT_ALLOWED);
21impl_fn!(not_acceptable, NOT_ACCEPTABLE);
22impl_fn!(proxy_authentication_required, PROXY_AUTHENTICATION_REQUIRED);
23impl_fn!(request_timeout, REQUEST_TIMEOUT);
24impl_fn!(conflict, CONFLICT);
25impl_fn!(gone, GONE);
26impl_fn!(length_required, LENGTH_REQUIRED);
27impl_fn!(precondition_failed, PRECONDITION_FAILED);
28impl_fn!(payload_too_large, PAYLOAD_TOO_LARGE);
29impl_fn!(uri_too_long, URI_TOO_LONG);
30impl_fn!(unsupported_media_type, UNSUPPORTED_MEDIA_TYPE);
31impl_fn!(range_not_satisfiable, RANGE_NOT_SATISFIABLE);
32impl_fn!(expectation_failed, EXPECTATION_FAILED);
33impl_fn!(im_a_teapot, IM_A_TEAPOT);
34
35impl_fn!(misdirected_request, MISDIRECTED_REQUEST);
36impl_fn!(unprocessable_entity, UNPROCESSABLE_ENTITY);
37impl_fn!(locked, LOCKED);
38impl_fn!(failed_dependency, FAILED_DEPENDENCY);
39
40impl_fn!(upgrade_required, UPGRADE_REQUIRED);
41
42impl_fn!(precondition_required, PRECONDITION_REQUIRED);
43impl_fn!(too_many_requests, TOO_MANY_REQUESTS);
44
45impl_fn!(
46 request_header_fields_too_large,
47 REQUEST_HEADER_FIELDS_TOO_LARGE
48);
49
50impl_fn!(unavailable_for_legal_reasons, UNAVAILABLE_FOR_LEGAL_REASONS);
51
52impl_fn!(internal_server_error, INTERNAL_SERVER_ERROR);
53impl_fn!(not_implemented, NOT_IMPLEMENTED);
54impl_fn!(bad_gateway, BAD_GATEWAY);
55impl_fn!(service_unavailable, SERVICE_UNAVAILABLE);
56impl_fn!(gateway_timeout, GATEWAY_TIMEOUT);
57impl_fn!(http_version_not_supported, HTTP_VERSION_NOT_SUPPORTED);
58impl_fn!(variant_also_negotiates, VARIANT_ALSO_NEGOTIATES);
59impl_fn!(insufficient_storage, INSUFFICIENT_STORAGE);
60impl_fn!(loop_detected, LOOP_DETECTED);
61
62impl_fn!(not_extended, NOT_EXTENDED);
63impl_fn!(
64 network_authentication_required,
65 NETWORK_AUTHENTICATION_REQUIRED
66);