All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tairitsu.ignotus.exception.business.PageNumberInvalidException.kt Maven / Gradle / Ivy

There is a newer version: 1.0.32
Show newest version
package com.tairitsu.ignotus.exception.business

import com.tairitsu.ignotus.exception.SingleApiException
import java.util.*

/**
 * 业务异常:页码格式错误
 */
class PageNumberInvalidException(parameterName: String, reason: Reason, pageStartsAt: Int = -1) :
    SingleApiException(400, CODE, "") {

    enum class Reason(val s: String) {
        FAIL_TO_PARSE("fail_to_parse"),
        OUT_OF_RANGE("out_of_range"),
    }

    companion object {
        const val CODE = "page_number_invalid"
    }

    init {
        detail = when (reason) {
            Reason.FAIL_TO_PARSE -> Translation.translateDetail(CODE, "fail_to_parse")
            Reason.OUT_OF_RANGE -> Translation.translateDetail(CODE, "out_of_range", Collections.singletonMap("min", pageStartsAt))
        }

        this.title = Translation.translateTitle(CODE)

        val t = HashMap()
        this.source = t
        t["parameter"] = parameterName
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy