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

Add Media types for RFC 7807 #2323

Merged
merged 1 commit into from Dec 20, 2018

Conversation

Projects
None yet
5 participants
@bigwheel
Copy link
Contributor

bigwheel commented Dec 15, 2018

@akka-ci

This comment has been minimized.

Copy link
Collaborator

akka-ci commented Dec 15, 2018

Thank you for your pull request! After a quick sanity check one of the team will reply with 'OK TO TEST' to kick off our automated validation on Jenkins. This compiles the project, runs the tests, and checks for things like binary compatibility and source code formatting. When two team members have also manually reviewed and (perhaps after asking for some amendments) accepted your contribution, it should be good to be merged.

For more details about our contributing process, check out CONTRIBUTING.md - and feel free to ask!

@raboof

This comment has been minimized.

Copy link
Member

raboof commented Dec 15, 2018

OK TO TEST

@akka-ci akka-ci added the validating label Dec 15, 2018

@raboof

raboof approved these changes Dec 15, 2018

Copy link
Member

raboof left a comment

Neat!

It would be interesting to write exception/rejection handlers that present errors in this format - could be a nice project outside of akka-http itself?

@akka-ci akka-ci added tested and removed validating labels Dec 15, 2018

@akka-ci

This comment has been minimized.

Copy link
Collaborator

akka-ci commented Dec 15, 2018

Test PASSed.

@bigwheel

This comment has been minimized.

Copy link
Contributor

bigwheel commented Dec 15, 2018

Thank you for response!

I wrote it already (this page was so helpful), and it works well as I expect.
However it is company private repository and I cannot access in weekend.

I'll share it as gist Monday afternoon.

P.S. Of cource I'll get permission to share its code by my boss.

@bigwheel

This comment has been minimized.

Copy link
Contributor

bigwheel commented Dec 17, 2018

https://gist.github.com/bigwheel/14e521488527f35bf6efed19c2453861

case class ErrorResponseBody private(
    `type`: URI,
    title: String
)

// https://doc.akka.io/docs/akka-http/10.1.3/routing-dsl/rejections.html?language=scala#customising-rejection-http-responses
private val rfc7807RejectionHandler = RejectionHandler.default.mapRejectionResponse {
  case res @ HttpResponse(_, _, entity: HttpEntity.Strict, _) =>
    val message = entity.data.utf8String

    res.copy(
      entity = HttpEntity(
        CustomMediaTypes.`application/problem+json`,
        ErrorResponseBody(new URI("about:blank"), message).toJson.prettyPrint
      )
    )
  case x => x
}

Works well in my product.

@jrudolph

This comment has been minimized.

Copy link
Member

jrudolph commented Dec 20, 2018

Created #2341 as a follow-up ticket to provide this RejectionHandler out of the box. Maybe you are interested to follow up with that, @bigwheel?

@jrudolph jrudolph merged commit 3dfe92f into akka:master Dec 20, 2018

3 checks passed

Jenkins PR Validation Test PASSed.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
typesafe-cla-validator All users have signed the CLA
Details
@jrudolph

This comment has been minimized.

Copy link
Member

jrudolph commented Dec 20, 2018

Thanks @bigwheel, good addition 👍.

@jrudolph jrudolph added this to the 10.1.7 milestone Dec 20, 2018

@bigwheel bigwheel deleted the bigwheel:media-type-for-rfc7807 branch Dec 20, 2018

@kazufumi-nishida-www

This comment has been minimized.

Copy link
Contributor

kazufumi-nishida-www commented Dec 20, 2018

@jrudolph thanks!
I will suggest more proper code for akka-http in #2341 because #2323 (comment) code depends on spray-json and its still simple method, not RejectionHandler.
I probably create PR for #2341 in Decemeber.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment