Skip to content

Commit cdc7bfd

Browse files
committed
refactor: Add default error messages if it's not parsed from the response
1 parent 8de3a96 commit cdc7bfd

11 files changed

+39
-0
lines changed

src/main/java/com/ibm/cloud/sdk/core/service/exception/BadRequestException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class BadRequestException extends ServiceResponseException {
3131
*/
3232
public BadRequestException(Response response) {
3333
super(HttpStatus.BAD_REQUEST, response);
34+
if (this.getMessage() == null) {
35+
this.setMessage("Bad request");
36+
}
3437
}
3538

3639
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/ConflictException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class ConflictException extends ServiceResponseException {
3333
*/
3434
public ConflictException(Response response) {
3535
super(HttpStatus.CONFLICT, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("");
38+
}
3639
}
3740

3841
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/ForbiddenException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class ForbiddenException extends ServiceResponseException {
3333
*/
3434
public ForbiddenException(Response response) {
3535
super(HttpStatus.FORBIDDEN, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("Forbidden: Service refused the request");
38+
}
3639
}
3740

3841
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/InternalServerErrorException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class InternalServerErrorException extends ServiceResponseException {
3333
*/
3434
public InternalServerErrorException(Response response) {
3535
super(HttpStatus.INTERNAL_SERVER_ERROR, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("Internal server error");
38+
}
3639
}
3740

3841
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/NotFoundException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class NotFoundException extends ServiceResponseException {
3333
*/
3434
public NotFoundException(Response response) {
3535
super(HttpStatus.NOT_FOUND, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("Not found");
38+
}
3639
}
3740

3841
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/RequestTooLargeException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class RequestTooLargeException extends ServiceResponseException {
3333
*/
3434
public RequestTooLargeException(Response response) {
3535
super(HttpStatus.REQUEST_TOO_LONG, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("Request too large: The request entity is larger than the server is able to process");
38+
}
3639
}
3740

3841
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/ServiceResponseException.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ public String getMessage() {
9090
return message;
9191
}
9292

93+
/**
94+
* Sets the error message.
95+
*
96+
* @param message the error message
97+
*/
98+
protected void setMessage(String message) {
99+
this.message = message;
100+
}
101+
93102
/**
94103
* Gets the headers.
95104
*

src/main/java/com/ibm/cloud/sdk/core/service/exception/ServiceUnavailableException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class ServiceUnavailableException extends ServiceResponseException {
3333
*/
3434
public ServiceUnavailableException(Response response) {
3535
super(HttpStatus.SERVICE_UNAVAILABLE, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("Service unavailable");
38+
}
3639
}
3740

3841
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/TooManyRequestsException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class TooManyRequestsException extends ServiceResponseException {
3232
*/
3333
public TooManyRequestsException(Response response) {
3434
super(TOO_MANY_REQUESTS, response);
35+
if (this.getMessage() == null) {
36+
this.setMessage("Too many requests");
37+
}
3538
}
3639

3740
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/UnauthorizedException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class UnauthorizedException extends ServiceResponseException {
3333
*/
3434
public UnauthorizedException(Response response) {
3535
super(HttpStatus.UNAUTHORIZED, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("Unauthorized: Access is denied due to invalid credentials. Tip: Did you set the endpoint?");
38+
}
3639
}
3740

3841
}

src/main/java/com/ibm/cloud/sdk/core/service/exception/UnsupportedException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class UnsupportedException extends ServiceResponseException {
3333
*/
3434
public UnsupportedException(Response response) {
3535
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, response);
36+
if (this.getMessage() == null) {
37+
this.setMessage("Unsupported media type");
38+
}
3639
}
3740

3841
}

0 commit comments

Comments
 (0)