Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
DNS Witch
Nomilo
Commits
67e12239
Commit
67e12239
authored
Apr 02, 2021
by
Gaël Berthaud-Müller
Browse files
better error handling
parent
7df4792e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
src/models/errors.rs
src/models/errors.rs
+11
-2
src/models/users.rs
src/models/users.rs
+3
-4
No files found.
src/models/errors.rs
View file @
67e12239
...
...
@@ -71,12 +71,21 @@ impl From<UserError> for ErrorResponse {
impl
<
S
>
Into
<
Outcome
<
S
,
ErrorResponse
>>
for
ErrorResponse
{
fn
into
(
self
)
->
Outcome
<
S
,
ErrorResponse
>
{
Outcome
::
Failure
(
(
self
.
status
.clone
(),
self
))
Outcome
::
Failure
(
self
.
into
(
))
}
}
impl
Into
<
(
Status
,
ErrorResponse
)
>
for
ErrorResponse
{
fn
into
(
self
)
->
(
Status
,
ErrorResponse
)
{
(
self
.status
.clone
(),
self
)
}
}
pub
fn
make_500
<
E
:
std
::
fmt
::
Debug
>
(
e
:
E
)
->
ErrorResponse
{
println!
(
"{:?}"
,
e
);
println!
(
"
Making 500 for Error:
{:?}"
,
e
);
ErrorResponse
::
new
(
Status
::
InternalServerError
,
"An unexpected error occured."
.into
())
}
pub
fn
make_500_tuple
<
E
:
std
::
fmt
::
Debug
>
(
e
:
E
)
->
(
Status
,
ErrorResponse
)
{
make_500
(
e
)
.into
()
}
src/models/users.rs
View file @
67e12239
...
...
@@ -20,7 +20,7 @@ use jsonwebtoken::{
use
crate
::
schema
::
*
;
use
crate
::
DbConn
;
use
crate
::
config
::
Config
;
use
crate
::
models
::
errors
::
ErrorResponse
;
use
crate
::
models
::
errors
::
{
ErrorResponse
,
make_500_tuple
}
;
const
BEARER
:
&
'static
str
=
"Bearer "
;
...
...
@@ -109,9 +109,8 @@ impl<'r> FromRequest<'r> for UserInfo {
return
ErrorResponse
::
from
(
UserError
::
MalformedHeader
)
.into
()
};
// TODO: Better error handling
let
config
=
request
.guard
::
<
State
<
Config
>>
()
.await
.unwrap
();
let
conn
=
request
.guard
::
<
DbConn
>
()
.await
.unwrap
();
let
config
=
try_outcome!
(
request
.guard
::
<
State
<
Config
>>
()
.await
.map_failure
(
make_500_tuple
));
let
conn
=
try_outcome!
(
request
.guard
::
<
DbConn
>
()
.await
.map_failure
(
make_500_tuple
));
let
token_data
=
AuthClaims
::
decode
(
token
,
&
config
.web_app.secret
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment