Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an exceptional commit message
- Loading branch information
1 parent
9f935bc
commit 69c1033
Showing
3 changed files
with
38 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
src/rest-ng/src/main/java/org/geoserver/rest/ResourceNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,15 +1,20 @@ | |||
package org.geoserver.rest; | package org.geoserver.rest; | ||
|
|
||
import org.springframework.http.HttpStatus; | |||
|
|||
/** | /** | ||
* Handling for 404 type exceptions | * Explicit exception for {@link HttpStatus#NOT_FOUND} (404) exceptions. | ||
*/ | */ | ||
public class ResourceNotFoundException extends RuntimeException { | public class ResourceNotFoundException extends RestException { | ||
|
|||
/** serialVersionUID */ | |||
private static final long serialVersionUID = 4656222203528783838L; | |||
|
|
||
public ResourceNotFoundException() { | public ResourceNotFoundException() { | ||
super(); | super("Not Found",HttpStatus.NOT_FOUND); | ||
} | } | ||
|
|
||
public ResourceNotFoundException(String s) { | public ResourceNotFoundException(String message) { | ||
super(s); | super(message, HttpStatus.NOT_FOUND); | ||
} | } | ||
} | } |
31 changes: 28 additions & 3 deletions
31
src/rest-ng/src/main/java/org/geoserver/rest/RestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,24 +1,49 @@ | |||
/* (c) 2017 - 2016 Open Source Geospatial Foundation - all rights reserved | |||
* This code is licensed under the GPL 2.0 license, available at the root | |||
* application directory. | |||
*/ | |||
package org.geoserver.rest; | package org.geoserver.rest; | ||
|
|
||
import org.springframework.http.HttpStatus; | import org.springframework.http.HttpStatus; | ||
|
|
||
/** | /** | ||
* General purpose rest exceptions | * Rest Exception including {@link HttpStatus} code. | ||
*/ | */ | ||
public class RestException extends RuntimeException { | public class RestException extends RuntimeException { | ||
/** serialVersionUID */ | |||
private static final long serialVersionUID = 5762645820684796082L; | |||
|
|||
private final HttpStatus status; | private final HttpStatus status; | ||
|
|
||
public RestException(String message, HttpStatus status) { | public RestException(String message, HttpStatus status) { | ||
super(message); | super(message); | ||
this.status = status; | this.status = status; | ||
} | } | ||
|
|
||
public RestException(String s, HttpStatus status, Throwable t) { | public RestException(String message, HttpStatus status, Throwable t) { | ||
super(s, t); | super(message, t); | ||
this.status = status; | this.status = status; | ||
} | } | ||
|
|
||
public HttpStatus getStatus() { | public HttpStatus getStatus() { | ||
return status; | return status; | ||
} | } | ||
|
|||
@Override | |||
public String toString() { | |||
StringBuilder builder = new StringBuilder(); | |||
builder.append(getClass().getName()); | |||
if( status != null ){ | |||
builder.append(" "); | |||
builder.append(status.value()); | |||
builder.append(" "); | |||
builder.append(status.name()); | |||
} | |||
String message = getLocalizedMessage(); | |||
if( message != null ){ | |||
builder.append(": "); | |||
builder.append( message ); | |||
} | |||
return builder.toString(); | |||
} | |||
} | } |