Skip to content

Commit d0bc921

Browse files
docs: use StatusCode instead of numbers in json-api impl example (#438)
1 parent 3e23f4b commit d0bc921

File tree

1 file changed

+11
-5
lines changed
  • examples/http-certification/json-api/src/backend/src

1 file changed

+11
-5
lines changed

examples/http-certification/json-api/src/backend/src/types.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ic_http_certification::{HttpRequest, HttpResponse};
1+
use ic_http_certification::{HttpRequest, HttpResponse, StatusCode};
22
use matchit::Params;
33
use serde::{Deserialize, Serialize};
44

@@ -23,15 +23,21 @@ impl<'a, T: Serialize> ApiResponse<'a, T> {
2323
}
2424

2525
pub fn not_found() -> Self {
26-
Self::err(404, "Not found".to_string())
26+
Self::err(StatusCode::NOT_FOUND, "Not found".to_string())
2727
}
2828

2929
pub fn not_allowed() -> Self {
30-
Self::err(405, "Method not allowed".to_string())
30+
Self::err(
31+
StatusCode::METHOD_NOT_ALLOWED,
32+
"Method not allowed".to_string(),
33+
)
3134
}
3235

33-
fn err(code: u16, message: String) -> Self {
34-
Self::Err { code, message }
36+
fn err(code: StatusCode, message: String) -> Self {
37+
Self::Err {
38+
code: code.as_u16(),
39+
message,
40+
}
3541
}
3642

3743
pub fn encode(&self) -> Vec<u8> {

0 commit comments

Comments
 (0)