-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Client exception deserializers added
- Loading branch information
lukasz.gryzbon
committed
Apr 19, 2022
1 parent
eef93b9
commit a3ff96c
Showing
9 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...c/main/kotlin/com/lsdconsulting/exceptionhandling/client/exception/BadGatewayException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.BAD_GATEWAY | ||
|
||
@JsonDeserialize(using = BadGatewayExceptionDeserializer::class) | ||
class BadGatewayException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, BAD_GATEWAY) | ||
constructor(message: String) : super(message, BAD_GATEWAY) | ||
} | ||
|
||
class BadGatewayExceptionDeserializer : JsonDeserializer<BadGatewayException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): BadGatewayException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return BadGatewayException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...c/main/kotlin/com/lsdconsulting/exceptionhandling/client/exception/BadRequestException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.BAD_REQUEST | ||
|
||
@JsonDeserialize(using = BadRequestExceptionDeserializer::class) | ||
class BadRequestException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, BAD_REQUEST) | ||
constructor(message: String) : super(message, BAD_REQUEST) | ||
} | ||
|
||
class BadRequestExceptionDeserializer : JsonDeserializer<BadRequestException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): BadRequestException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return BadRequestException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...src/main/kotlin/com/lsdconsulting/exceptionhandling/client/exception/ConflictException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.CONFLICT | ||
|
||
@JsonDeserialize(using = ConflictExceptionDeserializer::class) | ||
class ConflictException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, CONFLICT) | ||
constructor(message: String) : super(message, CONFLICT) | ||
} | ||
|
||
class ConflictExceptionDeserializer : JsonDeserializer<ConflictException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): ConflictException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return ConflictException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/kotlin/com/lsdconsulting/exceptionhandling/client/exception/GatewayTimeoutException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.GATEWAY_TIMEOUT | ||
|
||
@JsonDeserialize(using = GatewayTimeoutExceptionDeserializer::class) | ||
class GatewayTimeoutException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, GATEWAY_TIMEOUT) | ||
constructor(message: String) : super(message, GATEWAY_TIMEOUT) | ||
} | ||
|
||
class GatewayTimeoutExceptionDeserializer : JsonDeserializer<GatewayTimeoutException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): GatewayTimeoutException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return GatewayTimeoutException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/kotlin/com/lsdconsulting/exceptionhandling/client/exception/InternalServerException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR | ||
|
||
@JsonDeserialize(using = InternalServerExceptionDeserializer::class) | ||
class InternalServerException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, INTERNAL_SERVER_ERROR) | ||
constructor(message: String) : super(message, INTERNAL_SERVER_ERROR) | ||
} | ||
|
||
class InternalServerExceptionDeserializer : JsonDeserializer<InternalServerException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): InternalServerException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return InternalServerException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...src/main/kotlin/com/lsdconsulting/exceptionhandling/client/exception/NotFoundException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.NOT_FOUND | ||
|
||
@JsonDeserialize(using = NotFoundExceptionDeserializer::class) | ||
class NotFoundException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, NOT_FOUND) | ||
constructor(message: String) : super(message, NOT_FOUND) | ||
} | ||
|
||
class NotFoundExceptionDeserializer : JsonDeserializer<NotFoundException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): NotFoundException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return NotFoundException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/kotlin/com/lsdconsulting/exceptionhandling/client/exception/NotImplementedException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.NOT_IMPLEMENTED | ||
|
||
@JsonDeserialize(using = NotImplementedExceptionDeserializer::class) | ||
class NotImplementedException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, NOT_IMPLEMENTED) | ||
constructor(message: String) : super(message, NOT_IMPLEMENTED) | ||
} | ||
|
||
class NotImplementedExceptionDeserializer : JsonDeserializer<NotImplementedException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): NotImplementedException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return NotImplementedException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...otlin/com/lsdconsulting/exceptionhandling/client/exception/PreconditionFailedException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.PRECONDITION_FAILED | ||
|
||
@JsonDeserialize(using = PreconditionFailedExceptionDeserializer::class) | ||
class PreconditionFailedException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, PRECONDITION_FAILED) | ||
constructor(message: String) : super(message, PRECONDITION_FAILED) | ||
} | ||
|
||
class PreconditionFailedExceptionDeserializer : JsonDeserializer<PreconditionFailedException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): PreconditionFailedException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return PreconditionFailedException(errorResponse) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...otlin/com/lsdconsulting/exceptionhandling/client/exception/ServiceUnavailableException.kt
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package com.lsdconsulting.exceptionhandling.client.exception | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.lsdconsulting.exceptionhandling.api.ErrorResponse | ||
import org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE | ||
|
||
@JsonDeserialize(using = ServiceUnavailableExceptionDeserializer::class) | ||
class ServiceUnavailableException : ErrorResponseException { | ||
constructor(errorResponse: ErrorResponse?) : super(errorResponse, SERVICE_UNAVAILABLE) | ||
constructor(message: String) : super(message, SERVICE_UNAVAILABLE) | ||
} | ||
|
||
class ServiceUnavailableExceptionDeserializer : JsonDeserializer<ServiceUnavailableException>() { | ||
override fun deserialize(jp: JsonParser, dc: DeserializationContext): ServiceUnavailableException { | ||
val errorResponse = jp.readValueAs(ErrorResponse::class.java) | ||
return ServiceUnavailableException(errorResponse) | ||
} | ||
} |