-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: convert DbError
s to TokenserverError
s
#1327
Conversation
DbError
s to TokenserverErrors
DbError
s to TokenserverError
s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach. I wonder how much I can steal for the autopush redo.
0c74825
to
0d6ff3b
Compare
Just updated this comment to reflect the fact that we're returning 503 and not 500 for unhandled database errors |
@@ -52,31 +73,31 @@ impl TokenserverError { | |||
} | |||
} | |||
|
|||
pub fn invalid_key_id(description: &'static str) -> Self { | |||
pub fn invalid_key_id(description: String) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively you could take description: &str
for these to avoid to_owned()
at the call sites. You'll need to pass &foo
when you have owned String
s and it'll add an extra clone, but that's not the common case and IMO the small clone's worth it for convenience (but feel free to disagree and leave as is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and when you need to avoid that extra clone you can take an Into<Cow<&str>> but it's rarely worth that effort)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I had done it this way to make the clones obvious: in my mind, passing by reference suggests that the function doesn't need ownership, and it may suggest to the caller that the function is less expensive than it really is. But now I'm not so sure 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps having the function take Into<String>
is a good compromise? It allows flexibility, but it signals to the caller that the function does in fact need ownership
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with how it is now 😄 but good point, Into<String>
is simpler and works similarly and isn't too much trouble to specify as a generic type.
Description
The Tokenserver handler should always return a
TokenserverError
to ensure that errors are of the format expected by Tokenserver clients. In order to accomplish this, I needed to implementFrom<DbError>
forTokenserverError
. I treat any unhandledDbError
as an internal error, since SQLAlchemy errors on the Python Tokenserver raiseBackendError
s, which return 503s to the client.Testing
I've added an integration test to ensure that a
DbError
response has the correct formatCloses #1316