Skip to content

Commit

Permalink
Tweak error handling a little bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Sep 21, 2011
1 parent 6c99aa6 commit e78e665
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ class QuietErrorHandler extends ErrorHandler with Logging {
connection.getRequest.setHandled(true)

val jettyResponse = connection.getResponse
if (jettyResponse.getStatus == SC_INTERNAL_SERVER_ERROR) {
log.warn("Internal server error for %s: %s", baseRequest.getRequestURI, jettyResponse.getReason)
}

jettyResponse.setStatus(jettyResponse.getStatus)

val method = request.getMethod
if (method == HttpMethods.GET || method == HttpMethods.POST || method == HttpMethods.HEAD) {
response.setContentType(MimeTypes.TEXT_PLAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.yammer.dropwizard.examples

import com.codahale.fig.Configuration
import com.yammer.dropwizard.{Environment, Service}
import com.yammer.dropwizard.providers.OauthTokenProvider

object Example extends Service {
def name = "Example"
Expand All @@ -25,6 +24,7 @@ object Example extends Service {
environment.addResource(new HelloWorldResource)
environment.addResource(new UploadResource)
environment.addResource(new ProtectedResource)
environment.addResource(new SplodyResource)
environment.addHealthCheck(new DumbHealthCheck)
environment.manage(new StartableObject)
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/scala/com/yammer/dropwizard/examples/SplodyResource.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yammer.dropwizard.examples

import javax.ws.rs.core.StreamingOutput
import javax.ws.rs.{POST, GET, Path}
import java.io.OutputStream

@Path("/splode")
class SplodyResource {
private val dumb: String = null

/**
* An error which happens inside a Jersey resource.
*/
@GET
def splode() = dumb.toString

/**
* An error which happens outside of a Jersey resource.
*/
@POST
def sneakySplode(): StreamingOutput = new StreamingOutput {
def write(output: OutputStream) {
throw new RuntimeException("OH SWEET GOD WHAT")
}
}
}

0 comments on commit e78e665

Please sign in to comment.