1
- use crate :: cnb:: ing:: { IngReq , ING_API_BASE_URL } ;
1
+ use crate :: cnb:: ing:: IngReq ;
2
+ use crate :: http:: unit_or_err;
2
3
use crate :: infra:: http:: { setup_auth, APPLICATION_JSON } ;
3
- use crate :: infra:: result:: IntoResult ;
4
- use crate :: panic_hook;
4
+ use crate :: infra:: result:: ResultExt ;
5
+ use crate :: { openapi , panic_hook} ;
5
6
use alloc:: format;
6
- use alloc:: string:: { String , ToString } ;
7
- use anyhow:: { anyhow, Result } ;
8
- use core:: ops:: Not ;
7
+ use alloc:: string:: String ;
8
+ use anyhow:: Result ;
9
9
use reqwest:: header:: CONTENT_TYPE ;
10
10
use serde:: { Deserialize , Serialize } ;
11
11
use wasm_bindgen:: prelude:: * ;
@@ -32,7 +32,7 @@ impl IngReq {
32
32
parent_comment_id : Option < usize > ,
33
33
) -> Result < ( ) , String > {
34
34
panic_hook ! ( ) ;
35
- let url = format ! ( "{ING_API_BASE_URL}/{ing_id }/comments" ) ;
35
+ let url = openapi ! ( "/statuses/{ }/comments" , ing_id ) ;
36
36
37
37
let client = reqwest:: Client :: new ( ) . post ( url) ;
38
38
@@ -47,16 +47,10 @@ impl IngReq {
47
47
let result: Result < ( ) > = try {
48
48
let body = serde_json:: to_string_pretty ( & body) ?;
49
49
let req = req. body ( body) ;
50
-
51
50
let resp = req. send ( ) . await ?;
52
- let code = resp. status ( ) ;
53
-
54
- if code. is_success ( ) . not ( ) {
55
- let text = resp. text ( ) . await ?;
56
- anyhow ! ( "{}: {}" , code, text) . into_err ( ) ?
57
- }
51
+ unit_or_err ( resp) . await ?
58
52
} ;
59
53
60
- result. map_err ( |e| e . to_string ( ) )
54
+ result. err_to_string ( )
61
55
}
62
56
}
0 commit comments