Skip to content

Commit

Permalink
Added ServerException.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jul 26, 2018
1 parent 1d4ea6a commit 20d00c8
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main/java/io/sinistral/proteus/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,23 @@ public void send(final HttpServerExchange exchange) throws RuntimeException
public void send(final HttpHandler handler, final HttpServerExchange exchange) throws RuntimeException
{



final boolean hasBody = this.body != null;
final boolean hasEntity = this.entity != null;
final boolean hasError = this.throwable != null;

exchange.setStatusCode(this.status);



if (hasError)
{
exchange.putAttachment(DefaultResponseListener.EXCEPTION, throwable);
exchange.endExchange();
return;
}

if(this.location != null)
{
exchange.getResponseHeaders().put(Headers.LOCATION, this.location);
Expand All @@ -551,10 +566,6 @@ public void send(final HttpHandler handler, final HttpServerExchange exchange) t
return;
}

final boolean hasBody = this.body != null;
final boolean hasEntity = this.entity != null;
final boolean hasError = this.throwable != null;

if (this.hasHeaders)
{
long itr = this.headers.fastIterateNonEmpty();
Expand Down Expand Up @@ -593,12 +604,7 @@ else if (ServerPredicates.ACCEPT_XML_PREDICATE.resolve(exchange))
}
}

if (hasError)
{
exchange.putAttachment(DefaultResponseListener.EXCEPTION, throwable);

return;
}


if (hasBody)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
*
*/
package io.sinistral.proteus.server.exceptions;

import javax.ws.rs.core.Response.Status;

/**
* @author jbauer
*
*/
public class ServerException extends Exception
{
/**
*
*/
private static final long serialVersionUID = 8360356916374374408L;

private Integer status = 500;



public ServerException(int status)
{
super();
this.status = status;
}


public ServerException(String message, Throwable cause, int status)
{
super(message, cause);
this.status = status;
}

/**
* @param message
*/
public ServerException(String message, int status)
{
super(message);
this.status = status;
}


/**
* @param cause
*/
public ServerException(Throwable cause, int status)
{
super(cause);
this.status = status;
}

public ServerException(Status status)
{
super();
this.status = status.getStatusCode();
}


public ServerException(String message, Throwable cause, Status status)
{
super(message, cause);
this.status = status.getStatusCode();
}

/**
* @param message
*/
public ServerException(String message, Status status)
{
super(message);
this.status = status.getStatusCode();
}


/**
* @param cause
*/
public ServerException(Throwable cause, Status status)
{
super(cause);
this.status = status.getStatusCode();
}

/**
* @return the status
*/
public Integer getStatus()
{
return status;
}

/**
* @param status the status to set
*/
public void setStatus(Integer status)
{
this.status = status;
}


}

0 comments on commit 20d00c8

Please sign in to comment.