Skip to content

Commit

Permalink
Merge pull request #52 from cloudoptlab/3.x
Browse files Browse the repository at this point in the history
3.0.2.0-RELEASE
  • Loading branch information
T-baby authored Nov 8, 2021
2 parents 46ceb5f + 948ec38 commit abb891d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import net.cloudopt.next.validator.ValidatorTool
import net.cloudopt.next.waf.Wafer
import net.cloudopt.next.web.annotation.*
import net.cloudopt.next.web.handler.ErrorHandler
import java.lang.RuntimeException
import java.sql.Timestamp
import java.text.DateFormat
import java.time.LocalDate
Expand Down Expand Up @@ -204,7 +203,7 @@ class NextServerVerticle : CoroutineVerticle() {
}
} catch (e: Exception) {
e.printStackTrace()
Resource().init(context).fail(500)
Resource().init(context).fail(500, e)
}
}
}
Expand Down Expand Up @@ -238,7 +237,7 @@ class NextServerVerticle : CoroutineVerticle() {
context.next()
}
} catch (e: Exception) {
resource.fail(500)
resource.fail(500, e)
}
}
}
Expand Down Expand Up @@ -273,7 +272,7 @@ class NextServerVerticle : CoroutineVerticle() {
}
} catch (e: Exception) {
e.printStackTrace()
resource.fail(500)
resource.fail(500, e)
}
}
}
Expand Down Expand Up @@ -433,7 +432,7 @@ class NextServerVerticle : CoroutineVerticle() {
try {
arr[para] = getParaByType(para.findAnnotation<Parameter>()?.value ?: "", para, jsonObject)
} catch (e: IllegalArgumentException) {
resource.fail(400)
resource.fail(400, e)
e.printStackTrace()
return
}
Expand All @@ -443,11 +442,11 @@ class NextServerVerticle : CoroutineVerticle() {
try {
arr[para] = resource.getBodyJson(para.type.jvmErasure)
} catch (e: NullPointerException) {
resource.fail(400)
resource.fail(400, e)
e.printStackTrace()
return
} catch (e: IllegalArgumentException) {
resource.fail(400)
resource.fail(400, e)
e.printStackTrace()
return
}
Expand All @@ -473,7 +472,7 @@ class NextServerVerticle : CoroutineVerticle() {
logger.error(
e.message ?: "${resourceTable.url} has error occurred, but the error message could not be obtained "
)
resource.fail(500)
resource.fail(500, e)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import net.cloudopt.next.json.Jsoner.toJsonString
import net.cloudopt.next.waf.Wafer
import net.cloudopt.next.web.render.RenderFactory
import net.cloudopt.next.web.render.Template
import java.lang.RuntimeException
import kotlin.RuntimeException
import kotlin.reflect.KClass

open class Resource {
Expand Down Expand Up @@ -366,7 +366,7 @@ open class Resource {
* Ends the response. If no data has been written to the response body,
* the actual response won't get written until this method gets called.
* <p>
* Once the response has ended, it cannot be used any more.
* Once the response has ended, it cannot be used anymore.
*/
fun end() {
response.end()
Expand All @@ -382,7 +382,8 @@ open class Resource {
* @param statusCode Int the HTTP status code of the response
* @param throwable Throwable the throwable used when signalling failure
*/
fun fail(statusCode: Int, throwable: Throwable? = null) {
fun fail(statusCode: Int, throwable: Throwable = RuntimeException("Something is wrong, " +
"but no exception messages are caught.")) {
context.fail(statusCode, throwable)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FreemarkerRender : Render {
promise.complete(writer.toString())
} catch (e: Exception) {
promise.fail(e)
resource.fail(500)
resource.fail(500, e)
return@await
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class HbsRender : Render {
return@await
} catch (e: Exception) {
promise.fail(e)
resource.fail(500)
resource.fail(500, e)
return@await
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HtmlRender : Render {
return@await
} catch (e: Exception) {
promise.fail(e)
resource.fail(500)
resource.fail(500, e)
return@await
}
val bufferedReader = BufferedReader(InputStreamReader(inputStream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class JsonRender : Render {
} catch (e: Exception) {
promise.fail(e)
e.printStackTrace()
resource.fail(500)
resource.fail(500, e)
return@await
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class RestController : Resource() {

@GET("/defaultError")
fun defaultError() {
fail(402)
fail(500)
}


@GET("/customError")
fun customError() {
fail(401, RuntimeException("401"))
fail(500, RuntimeException("Test Error"))
}

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project_version=3.0.2.0
project_version=3.0.3.0-RELEASE
java_version=11
kotlin_version=1.5.0
kotlinx_version=1.5.0
Expand Down

0 comments on commit abb891d

Please sign in to comment.