@@ -11,6 +11,9 @@ use git2;
11
11
12
12
use util:: json_response;
13
13
14
+ #[ deriving( Encodable ) ] struct Error { detail : String }
15
+ #[ deriving( Encodable ) ] struct Bad { errors : Vec < Error > }
16
+
14
17
pub trait CargoError : Send {
15
18
fn description ( & self ) -> String ;
16
19
fn detail ( & self ) -> Option < String > { None }
@@ -40,9 +43,6 @@ pub trait CargoError: Send {
40
43
}
41
44
42
45
fn response ( & self ) -> Option < Response > {
43
- #[ deriving( Encodable ) ] struct Error { detail : String }
44
- #[ deriving( Encodable ) ] struct Bad { errors : Vec < Error > }
45
-
46
46
if self . human ( ) {
47
47
Some ( json_response ( & Bad {
48
48
errors : vec ! [ Error { detail: self . description( ) } ]
@@ -242,11 +242,13 @@ impl CargoError for Unauthorized {
242
242
fn description ( & self ) -> String { "unauthorized" . to_string ( ) }
243
243
244
244
fn response ( & self ) -> Option < Response > {
245
- Some ( Response {
246
- status : ( 403 , "Forbidden" ) ,
247
- headers : HashMap :: new ( ) ,
248
- body : box MemReader :: new ( Vec :: new ( ) ) ,
249
- } )
245
+ let mut response = json_response ( & Bad {
246
+ errors : vec ! [ Error {
247
+ detail: "must be logged in to perform that action" . to_string( ) ,
248
+ } ] ,
249
+ } ) ;
250
+ response. status = ( 403 , "Forbidden" ) ;
251
+ return Some ( response) ;
250
252
}
251
253
}
252
254
0 commit comments