Skip to content

Commit

Permalink
Merge pull request #79 from waterdog-oss/development
Browse files Browse the repository at this point in the history
ErrorCode enum converted to class
  • Loading branch information
felix19350 authored Feb 3, 2021
2 parents 5fe1eeb + 9624dfd commit 198c0fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package mobi.waterdog.rest.template.exception

import io.ktor.http.HttpStatusCode

enum class ErrorCode(val httpStatusCode: HttpStatusCode, val messageCode: String) {
// client errors
InvalidUserInput(HttpStatusCode.BadRequest, "client_error.invalid_parameters"),
NotFound(HttpStatusCode.NotFound, "client_error.not_found"),
class ErrorCode(val httpStatusCode: HttpStatusCode, val messageCode: String)

// server errors
NotImplemented(HttpStatusCode.NotImplemented, "server_error.not_implemented")
object ErrorCodes {
val InvalidUserInput = ErrorCode(HttpStatusCode.BadRequest, "client_error.invalid_parameters")
val NotFound = ErrorCode(HttpStatusCode.NotFound, "client_error.not_found")

// TODO fill with all possible app errors
// server errors
val NotImplemented = ErrorCode(HttpStatusCode.NotImplemented, "server_error.not_implemented")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mobi.waterdog.rest.template.validation

import mobi.waterdog.rest.template.exception.AppException
import mobi.waterdog.rest.template.exception.ErrorCode
import mobi.waterdog.rest.template.exception.ErrorCodes
import mobi.waterdog.rest.template.exception.ErrorDefinition
import org.valiktor.Constraint
import org.valiktor.ConstraintViolationException
Expand Down Expand Up @@ -68,7 +68,7 @@ abstract class Validatable<T> {

private fun valiktorException2AppException(valiktorEx: ConstraintViolationException): AppException {
val validationException = AppException(
code = ErrorCode.InvalidUserInput,
code = ErrorCodes.InvalidUserInput,
title = "Invalid content for class ${this::class.qualifiedName}, check invalid fields in errors"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mobi.waterdog.rest.template.tests.core.persistance.sql

import mobi.waterdog.rest.template.exception.AppException
import mobi.waterdog.rest.template.exception.ErrorCode
import mobi.waterdog.rest.template.exception.ErrorCodes
import mobi.waterdog.rest.template.pagination.PageRequest
import mobi.waterdog.rest.template.pagination.SortField
import mobi.waterdog.rest.template.tests.core.model.Person
Expand Down Expand Up @@ -57,7 +57,7 @@ class PersonRepositoryImpl : PersonRepository {
"name" -> Persons.name
"birthday" -> Persons.birthday
else -> throw AppException(
ErrorCode.NotImplemented,
ErrorCodes.NotImplemented,
"Sort by column '${sort.field}' in Person table not " +
"implemented."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package mobi.waterdog.rest.template.tests.core.service

import mobi.waterdog.rest.template.database.DatabaseConnection
import mobi.waterdog.rest.template.exception.AppException
import mobi.waterdog.rest.template.exception.ErrorCode
import mobi.waterdog.rest.template.exception.ErrorCodes
import mobi.waterdog.rest.template.pagination.PageRequest
import mobi.waterdog.rest.template.tests.core.model.Car
import mobi.waterdog.rest.template.tests.core.model.CarSaveCommand
Expand Down Expand Up @@ -43,7 +43,7 @@ class CarServiceImpl(
override suspend fun updateCar(car: Car): Car {
return dbc.suspendedQuery {
if (!exists(car.id)) {
throw AppException(ErrorCode.NotFound, "Could not find car with id '${car.id}'.")
throw AppException(ErrorCodes.NotFound, "Could not find car with id '${car.id}'.")
}
carRepository.update(car)
}
Expand Down

0 comments on commit 198c0fe

Please sign in to comment.