-
Notifications
You must be signed in to change notification settings - Fork 1
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 #4 from nextbss/custom-error-responses
NF - Custom error responses
- Loading branch information
Showing
18 changed files
with
248 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ build/ | |
### VS Code ### | ||
.vscode/ | ||
settings.xml | ||
target |
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
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/ao/co/nextbss/requirekt/AAACustomErrorViewModel.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ao.co.nextbss.requirekt | ||
|
||
import co.ao.nextbss.requirekt.annotation.ErrorResponse | ||
|
||
@ErrorResponse | ||
class AAACustomErrorViewModel( | ||
var status: Int = 0, | ||
var code: String? = null, | ||
var message: String? = null, | ||
var type: String? = null): AbstractErrorResponse() { | ||
|
||
override fun toJSON(vararg args: ArrayList<Any>): String { | ||
status = fromArgsAsInt(0, args) | ||
code = fromArgsAsString(1, args) | ||
message = fromArgsAsString(2, args) | ||
type = fromArgsAsString(3, args) | ||
return super.toJSON() | ||
} | ||
} | ||
|
||
|
||
|
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/ao/co/nextbss/requirekt/AbstractErrorResponse.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ao.co.nextbss.requirekt | ||
|
||
import co.ao.nextbss.requirekt.interfaces.Converter | ||
|
||
abstract class AbstractErrorResponse: Converter { | ||
override fun toJSON(vararg args: ArrayList<Any>): String { | ||
return ErrorWrapper().toJsonString(this) | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/ao/co/nextbss/requirekt/CustomErrorBeanFinder.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ao.co.nextbss.requirekt | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.core.env.Environment | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
@ComponentScan(basePackages = []) | ||
open class CustomErrorBeanFinder { | ||
@Autowired | ||
lateinit var errors: List<AbstractErrorResponse> | ||
|
||
@Autowired | ||
lateinit var environment: Environment | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/ao/co/nextbss/requirekt/DefaultErrorViewModel.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ao.co.nextbss.requirekt | ||
|
||
import ao.co.nextbss.requirekt.AbstractErrorResponse | ||
import co.ao.nextbss.requirekt.annotation.ErrorResponse | ||
|
||
@ErrorResponse | ||
class DefaultErrorViewModel(val status: Int?, | ||
val code: String?, | ||
val message: String? | ||
) : AbstractErrorResponse() { | ||
override fun toJSON(vararg args: ArrayList<Any>): String { | ||
return super.toJSON() | ||
} | ||
} |
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,10 @@ | ||
package ao.co.nextbss.requirekt | ||
|
||
import co.ao.nextbss.requirekt.annotation.ErrorResponse | ||
|
||
@ErrorResponse | ||
open class ErrorResponse: AbstractErrorResponse() { | ||
override fun toJSON(vararg args: ArrayList<Any>): String { | ||
return ErrorWrapper().toJsonString(this) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ao.co.nextbss.requirekt | ||
|
||
import org.springframework.beans.BeansException | ||
import org.springframework.context.ApplicationContext | ||
import org.springframework.context.ApplicationContextAware | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SpringContext : ApplicationContextAware { | ||
@Throws(BeansException::class) | ||
override fun setApplicationContext(context: ApplicationContext?) { | ||
Companion.context = context | ||
} | ||
|
||
companion object { | ||
private var context: ApplicationContext? = null | ||
|
||
fun <T : Any?> getBean(beanClass: Class<T>?): T { | ||
return context!!.getBean(beanClass) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/ao/co/nextbss/requirekt/annotation/ErrorResponse.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package co.ao.nextbss.requirekt.annotation | ||
|
||
import org.springframework.stereotype.Component | ||
|
||
@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@MustBeDocumented | ||
@Component | ||
annotation class ErrorResponse( | ||
|
||
) |
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,17 @@ | ||
package ao.co.nextbss.requirekt | ||
|
||
fun fromArgs(index: Int, args: Array<out ArrayList<Any>>): Any { | ||
return args[0][index] | ||
} | ||
|
||
fun fromArgsAsInt(index: Int, args: Array<out ArrayList<Any>>): Int { | ||
return args[0][index] as Int | ||
} | ||
|
||
fun fromArgsAsString(index: Int, args: Array<out ArrayList<Any>>): String { | ||
return args[0][index] as String | ||
} | ||
|
||
fun fromArgsAsFloat(index: Int, args: Array<out ArrayList<Any>>): Float { | ||
return args[0][index] as Float | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/ao/co/nextbss/requirekt/interfaces/Converter.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package co.ao.nextbss.requirekt.interfaces | ||
|
||
interface Converter { | ||
fun toJSON(vararg args: ArrayList<Any>): String | ||
} |
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
Binary file not shown.