-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from kdhrubo/feature/119_exception_handling
Exception handling for procedure and function calls
- Loading branch information
Showing
4 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/homihq/db2rest/exception/RpcException.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.homihq.db2rest.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ProblemDetail; | ||
import org.springframework.web.ErrorResponseException; | ||
|
||
import java.net.URI; | ||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
public class RpcException extends ErrorResponseException { | ||
|
||
public RpcException(String subRoutineName, Map<String, Object> inParams) { | ||
super(HttpStatus.BAD_REQUEST, | ||
asProblemDetail("Procedure/Function name: " | ||
+ subRoutineName + ", IN parameters: " | ||
+ inParams.entrySet()), null); | ||
} | ||
|
||
private static ProblemDetail asProblemDetail(String message) { | ||
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, message); | ||
problemDetail.setTitle("Invalid Procedure/Function name or IN parameter mismatch"); | ||
problemDetail.setDetail(message); | ||
problemDetail.setType(URI.create("https://github.com/kdhrubo/db2rest/invalid-subroutine-request")); | ||
problemDetail.setProperty("errorCategory", "Invalid-SubRoutine-Request"); | ||
problemDetail.setProperty("timestamp", Instant.now()); | ||
return problemDetail; | ||
} | ||
} |
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
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
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