-
Notifications
You must be signed in to change notification settings - Fork 415
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
Make Endpoint respond with a 401 status code if the Authorization header is missing #3281
base: main
Are you sure you want to change the base?
Conversation
@@ -340,9 +340,10 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType]( | |||
case Some(HttpCodecError.CustomError("SchemaTransformationFailure", message)) | |||
if maybeUnauthedResponse.isDefined && message.endsWith(" auth required") => | |||
maybeUnauthedResponse.get | |||
case Some(_) => | |||
case Some(HttpCodecError.MissingAuthorizationHeader) => | |||
Handler.succeed(Response.unauthorized) |
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.
Let me know if this should be reported the same way is any other missing header.
case Some(_) => | ||
case Some(HttpCodecError.MissingAuthorizationHeader) => | ||
Handler.succeed(Response.unauthorized) | ||
case Some(error) => |
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.
Not sure why it was not written this way, as it looks like in this case asHttpCodecError
provides the same value as cause.defects.head.asInstanceOf[HttpCodecError]
.
@@ -33,6 +33,9 @@ object HttpCodecError { | |||
final case class MissingHeader(headerName: String) extends HttpCodecError { | |||
def message = s"Missing header $headerName" | |||
} | |||
final case object MissingAuthorizationHeader extends HttpCodecError { |
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 believe introducing a special case for that purpose helps with reasoning. Let me know if you'd like this to be implement using MissingHeader
.
/claim #3235