-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientHelpers.go.tmpl
36 lines (30 loc) · 1.01 KB
/
clientHelpers.go.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{{define "clientHelpers"}}
{{- $webrpcErrors := .WebrpcErrors -}}
{{- $schemaErrors := .SchemaErrors -}}
// region Errors
enum class ErrorKind(val code: Int) {
{{- range $_, $error := $webrpcErrors}}
{{toUpper (snakeCase $error.Name)}}({{$error.Code}}),
{{- end }}
{{- range $_, $error := $schemaErrors}}
{{toUpper (snakeCase $error.Name)}}({{$error.Code}}),
{{- end }}
UNKNOWN(-999);
companion object {
fun fromCode(code: Int): ErrorKind {
return ErrorKind.values().find { it.code == code } ?: UNKNOWN
}
}
}
@JsonClass(generateAdapter = true)
data class WebRpcError(
@Json(name = "error") val error: String,
@Json(name = "code") val code: Int,
@Json(name = "msg") override val message: String,
@Json(name = "cause") val causeString: String,
@Json(name = "status") val status: Int,
@Transient val errorKind: ErrorKind = ErrorKind.fromCode(code),
@Transient override val cause: Throwable? = null,
) : Throwable()
// endregion
{{end}}