Skip to content

Commit

Permalink
Improve formatting of UnexpectedResponse.getMessage
Browse files Browse the repository at this point in the history
This lists each header of the response on its own line instead of
having them all on one line.
  • Loading branch information
fthomas committed Nov 15, 2021
1 parent cc04fcf commit 30b2ad5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,10 @@ final case class UnexpectedResponse(
) extends RuntimeException
with NoStackTrace {
override def getMessage: String =
s"uri: $uri\nmethod: $method\nstatus: $status\nheaders: $headers\nbody: $body"
s"""|uri: $uri
|method: $method
|status: $status
|headers:
|${headers.headers.map(h => s" ${h.show}").mkString("\n")}
|body: $body""".stripMargin
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.scalasteward.core.util

import munit.FunSuite
import org.http4s.{Header, Headers, Method, Status, Uri}
import org.typelevel.ci.CIString

class UnexpectedResponseTest extends FunSuite {
test("getMessage") {
val unexpected = UnexpectedResponse(
Uri.unsafeFromString("https://api.github.com/repos/foo/bar/pulls"),
Method.POST,
Headers(
Header.Raw(CIString("access-control-allow-origin"), "*"),
Header.Raw(CIString("content-type"), "application/json; charset=utf-8")
),
Status.Forbidden,
"""{ message: "nope" }"""
)
val expected =
"""|uri: https://api.github.com/repos/foo/bar/pulls
|method: POST
|status: 403 Forbidden
|headers:
| access-control-allow-origin: *
| content-type: application/json; charset=utf-8
|body: { message: "nope" }""".stripMargin
assertEquals(unexpected.getMessage, expected)
}
}

0 comments on commit 30b2ad5

Please sign in to comment.