Skip to content

Commit f7f10d5

Browse files
committed
Fix implementation
1 parent 5056bcd commit f7f10d5

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

zio-http/shared/src/main/scala/zio/http/Header.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ object Header {
8787
private val errorConstructor =
8888
new ErrorConstructor {
8989
override def missing(fieldName: String): HttpCodecError =
90-
if (fieldName == Header.Authorization.name)
91-
HttpCodecError.MissingAuthorizationHeader
92-
else
93-
HttpCodecError.MissingHeader(fieldName)
90+
HttpCodecError.MissingHeader(fieldName)
9491

9592
override def missingAll(fieldNames: Chunk[String]): HttpCodecError =
9693
HttpCodecError.MissingHeaders(fieldNames)

zio-http/shared/src/main/scala/zio/http/codec/HttpCodecError.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import zio.{Cause, Chunk}
2323
import zio.schema.codec.DecodeError
2424
import zio.schema.validation.ValidationError
2525

26-
import zio.http.Header.HeaderType
2726
import zio.http.{Path, Status}
2827

2928
sealed trait HttpCodecError extends Exception with NoStackTrace with Product with Serializable {
@@ -34,9 +33,6 @@ object HttpCodecError {
3433
final case class MissingHeader(headerName: String) extends HttpCodecError {
3534
def message = s"Missing header $headerName"
3635
}
37-
case object MissingAuthorizationHeader extends HttpCodecError {
38-
def message = "Missing header Authorization"
39-
}
4036
final case class MissingHeaders(headerNames: Chunk[String]) extends HttpCodecError {
4137
def message = s"Missing headers ${headerNames.mkString(", ")}"
4238
}

zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import zio.schema.Schema
2727

2828
import zio.http.Header.Accept.MediaTypeWithQFactor
2929
import zio.http._
30-
import zio.http.codec.{StatusCodec, _}
30+
import zio.http.codec._
3131
import zio.http.endpoint.Endpoint.{OutErrors, defaultMediaTypes}
3232

3333
/**
@@ -340,9 +340,12 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
340340
case Some(HttpCodecError.CustomError("SchemaTransformationFailure", message))
341341
if maybeUnauthedResponse.isDefined && message.endsWith(" auth required") =>
342342
maybeUnauthedResponse.get
343-
case Some(HttpCodecError.MissingAuthorizationHeader) =>
343+
case Some(HttpCodecError.MissingHeader(headerName)) if headerName == Header.Authorization.name =>
344344
Handler.succeed(Response.unauthorized)
345-
case Some(error) =>
345+
case Some(HttpCodecError.MissingHeaders(headerNames))
346+
if headerNames.contains(Header.Authorization.name) =>
347+
Handler.succeed(Response.unauthorized)
348+
case Some(error) =>
346349
Handler.fromFunctionZIO { (request: zio.http.Request) =>
347350
val response = {
348351
val outputMediaTypes =
@@ -356,7 +359,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
356359
}
357360
ZIO.succeed(response)
358361
}
359-
case None =>
362+
case None =>
360363
Handler.failCause(cause)
361364
}
362365
}

0 commit comments

Comments
 (0)