Skip to content

Commit

Permalink
Improved response messaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jul 19, 2018
1 parent dbcb3ba commit 76b904f
Showing 1 changed file with 60 additions and 23 deletions.
83 changes: 60 additions & 23 deletions src/main/java/io/sinistral/proteus/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void setStatus(int status)
* @param contentType
* the contentType to set
*/
public void setContentType(String contentType)
protected void setContentType(String contentType)
{
this.contentType = contentType;

Expand Down Expand Up @@ -281,6 +281,13 @@ public ServerResponse<T> redirectPermanently(String location)
this.status = StatusCodes.MOVED_PERMANENTLY;;
return this;
}

public ServerResponse<T> found()
{
this.status = StatusCodes.FOUND;
return this;
}


public ServerResponse<T> accepted()
{
Expand All @@ -296,13 +303,12 @@ public ServerResponse<T> badRequest()

public ServerResponse<T> badRequest(Throwable t)
{
this.status = StatusCodes.BAD_REQUEST;
this.throwable = t;
return this;
return this.badRequest();
}
public ServerResponse<T> badRequest(String message)
{
return this.badRequest(new Throwable(message));
return this.errorMessage(message).badRequest();
}

public ServerResponse<T> internalServerError()
Expand All @@ -313,14 +319,13 @@ public ServerResponse<T> internalServerError()

public ServerResponse<T> internalServerError(Throwable t)
{
this.status = StatusCodes.INTERNAL_SERVER_ERROR;
this.throwable = t;
return this;
return this.internalServerError();
}

public ServerResponse<T> internalServerError(String message)
{
return this.internalServerError(new Throwable(message));
return this.errorMessage(message).internalServerError();
}

public ServerResponse<T> created()
Expand All @@ -337,14 +342,13 @@ public ServerResponse<T> notFound()

public ServerResponse<T> notFound(Throwable t)
{
this.status = StatusCodes.NOT_FOUND;
this.throwable = t;
return this;
return this.notFound();
}

public ServerResponse<T> notFound(String message)
{
return this.notFound(new Throwable(message));
return this.errorMessage(message).notFound();
}


Expand All @@ -355,41 +359,74 @@ public ServerResponse<T> forbidden()
}

public ServerResponse<T> forbidden(Throwable t)
{
this.status = StatusCodes.FORBIDDEN;
{
this.throwable = t;
return this;
return this.forbidden();
}

public ServerResponse<T> forbidden(String message)
{
return this.forbidden(new Throwable(message));
return this.errorMessage(message).forbidden();
}


public ServerResponse<T> found()
public ServerResponse<T> noContent()
{
this.status = StatusCodes.FOUND;
this.status = StatusCodes.NO_CONTENT;
return this;
}

public ServerResponse<T> noContent(Throwable t)
{
this.throwable = t;
return this.noContent();
}

public ServerResponse<T> noContent()

public ServerResponse<T> noContent(String message)
{
return this.errorMessage(message).noContent();
}

public ServerResponse<T> serviceUnavailable()
{
this.status = StatusCodes.NO_CONTENT;
this.status = StatusCodes.SERVICE_UNAVAILABLE;
return this;
}

public ServerResponse<T> noContent(Throwable t)
public ServerResponse<T> serviceUnavailable(Throwable t)
{
this.status = StatusCodes.NO_CONTENT;
this.throwable = t;
return this.serviceUnavailable();
}


public ServerResponse<T> serviceUnavailable(String message)
{
return this.errorMessage(message).serviceUnavailable();
}

public ServerResponse<T> unauthorized()
{
this.status = StatusCodes.UNAUTHORIZED;
return this;
}

public ServerResponse<T> unauthorized(Throwable t)
{
this.throwable = t;
return this.unauthorized();
}


public ServerResponse<T> noContent(String message)
public ServerResponse<T> unauthorized(String message)
{
return this.errorMessage(message).unauthorized();
}

public ServerResponse<T> errorMessage(String message)
{
return this.noContent(new Throwable(message));
this.throwable = new Throwable(message);
return this;
}

public ServerResponse<T> withIoCallback(IoCallback ioCallback)
Expand Down

0 comments on commit 76b904f

Please sign in to comment.