Skip to main content

apimock_server/response/
error_response.rs

1use hyper::{HeaderMap, StatusCode};
2
3use super::status_code_response::{status_code_response, status_code_response_with_message};
4use crate::types::BoxBody;
5
6/// error response on http BAD_REQUEST (400)
7pub fn bad_request_response(
8    message: &str,
9    request_headers: &HeaderMap,
10    cors_allow_credentials_origins: &[String],
11) -> Result<hyper::Response<BoxBody>, hyper::http::Error> {
12    status_code_response_with_message(
13        &StatusCode::BAD_REQUEST,
14        message,
15        None,
16        request_headers,
17        cors_allow_credentials_origins,
18    )
19}
20
21/// error response on http PAYLOAD_TOO_LARGE (413) — RFC 068 S-02: a
22/// request body over the configured limit, refused before it is
23/// buffered.
24pub fn payload_too_large_response(
25    message: &str,
26    request_headers: &HeaderMap,
27    cors_allow_credentials_origins: &[String],
28) -> Result<hyper::Response<BoxBody>, hyper::http::Error> {
29    status_code_response_with_message(
30        &StatusCode::PAYLOAD_TOO_LARGE,
31        message,
32        None,
33        request_headers,
34        cors_allow_credentials_origins,
35    )
36}
37
38/// error response on http NOT_FOUND (404)
39pub fn not_found_response(
40    request_headers: &HeaderMap,
41    cors_allow_credentials_origins: &[String],
42) -> Result<hyper::Response<BoxBody>, hyper::http::Error> {
43    status_code_response(
44        &StatusCode::NOT_FOUND,
45        None,
46        request_headers,
47        cors_allow_credentials_origins,
48    )
49}
50
51/// error response on http INTERNAL_SERVER_ERROR (500)
52pub fn internal_server_error_response(
53    message: &str,
54    request_headers: &HeaderMap,
55    cors_allow_credentials_origins: &[String],
56) -> Result<hyper::Response<BoxBody>, hyper::http::Error> {
57    status_code_response_with_message(
58        &StatusCode::INTERNAL_SERVER_ERROR,
59        message,
60        None,
61        request_headers,
62        cors_allow_credentials_origins,
63    )
64}