Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
e5c71195
Unverified
Commit
e5c71195
authored
3 years ago
by
Timo Kösters
Browse files
Options
Downloads
Patches
Plain Diff
feat: forward federation errors to the client
parent
1939e628
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/error.rs
+17
-4
17 additions, 4 deletions
src/error.rs
src/server_server.rs
+17
-8
17 additions, 8 deletions
src/server_server.rs
with
34 additions
and
12 deletions
src/error.rs
+
17
−
4
View file @
e5c71195
use
log
::{
error
,
warn
};
use
ruma
::
api
::
client
::{
error
::
ErrorKind
,
r0
::
uiaa
::
UiaaInfo
};
use
ruma
::{
api
::
client
::{
error
::{
Error
as
RumaError
,
ErrorKind
},
r0
::
uiaa
::
UiaaInfo
,
},
ServerName
,
};
use
thiserror
::
Error
;
#[cfg(feature
=
"conduit_bin"
)]
...
...
@@ -10,7 +16,7 @@
response
::{
self
,
Responder
},
Request
,
},
ruma
::
api
::
client
::
{
error
::
Error
as
RumaError
,
r0
::
uiaa
::
UiaaResponse
}
,
ruma
::
api
::
client
::
r0
::
uiaa
::
UiaaResponse
,
};
pub
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Error
>
;
...
...
@@ -33,6 +39,8 @@ pub enum Error {
source
:
reqwest
::
Error
,
},
#[error(
"{0}"
)]
FederationError
(
Box
<
ServerName
>
,
RumaError
),
#[error(
"{0}"
)]
BadServerResponse
(
&
'static
str
),
#[error(
"{0}"
)]
BadConfig
(
&
'static
str
),
...
...
@@ -66,8 +74,13 @@ impl<'r, 'o> Responder<'r, 'o> for Error
'o
:
'r
,
{
fn
respond_to
(
self
,
r
:
&
'r
Request
<
'_
>
)
->
response
::
Result
<
'o
>
{
if
let
Self
::
Uiaa
(
uiaainfo
)
=
&
self
{
return
RumaResponse
::
from
(
UiaaResponse
::
AuthResponse
(
uiaainfo
.clone
()))
.respond_to
(
r
);
if
let
Self
::
Uiaa
(
uiaainfo
)
=
self
{
return
RumaResponse
::
from
(
UiaaResponse
::
AuthResponse
(
uiaainfo
))
.respond_to
(
r
);
}
if
let
Self
::
FederationError
(
origin
,
mut
error
)
=
self
{
error
.message
=
format!
(
"Answer from {}: {}"
,
origin
,
error
.message
);
return
RumaResponse
::
from
(
error
)
.respond_to
(
r
);
}
let
message
=
format!
(
"{}"
,
self
);
...
...
This diff is collapsed.
Click to expand it.
src/server_server.rs
+
17
−
8
View file @
e5c71195
...
...
@@ -9,7 +9,7 @@
use
rocket
::{
response
::
content
::
Json
,
State
};
use
ruma
::{
api
::{
client
::
error
::
ErrorKind
,
client
::
error
::
{
Error
as
RumaError
,
ErrorKind
}
,
federation
::{
device
::
get_devices
::{
self
,
v1
::
UserDevice
},
directory
::{
get_public_rooms
,
get_public_rooms_filtered
},
...
...
@@ -27,7 +27,7 @@
query
::{
get_profile_information
,
get_room_information
},
transactions
::{
edu
::
Edu
,
send_transaction_message
},
},
IncomingResponse
,
OutgoingRequest
,
OutgoingResponse
,
SendAccessToken
,
EndpointError
,
IncomingResponse
,
OutgoingRequest
,
OutgoingResponse
,
SendAccessToken
,
},
directory
::{
IncomingFilter
,
IncomingRoomNetwork
},
events
::{
...
...
@@ -261,12 +261,21 @@ pub async fn send_request<T: OutgoingRequest>(
);
}
let
response
=
T
::
IncomingResponse
::
try_from_http_response
(
http_response_builder
.body
(
body
)
.expect
(
"reqwest body is valid http body"
),
);
response
.map_err
(|
_
|
Error
::
BadServerResponse
(
"Server returned bad response."
))
let
http_response
=
http_response_builder
.body
(
body
)
.expect
(
"reqwest body is valid http body"
);
if
status
==
200
{
let
response
=
T
::
IncomingResponse
::
try_from_http_response
(
http_response
);
response
.map_err
(|
_
|
Error
::
BadServerResponse
(
"Server returned bad 200 response."
))
}
else
{
Err
(
Error
::
FederationError
(
destination
.to_owned
(),
RumaError
::
try_from_http_response
(
http_response
)
.map_err
(|
_
|
{
Error
::
BadServerResponse
(
"Server returned bad error response."
)
})
?
,
))
}
}
Err
(
e
)
=>
Err
(
e
.into
()),
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment