Zero system provide simple error define for user.
In your class path, create a new up.god.file named vertx-error.yml
,the format is as following:
E100001: User defined Error {0}, details = {1}
The detail implementation used MessageFormat, do not support named parameters.
Create new class that you wanted as following
import io.horizon.exception.WebException;
public class TestRequestException extends
WebException {
public TestRequestException(final Class<?> clazz,
final String name,
final String detail) {
super(clazz, name, detail);
}
@Override
public int getCode() {
return -100001;
}
}
Please ignore the first parameter Class<?>
, it's for Zero to detect the error happened class position;
The rest parameters could be pass any length, you could call super(clazz, arg0, arg1, ...)
Be sure to write the getCode()
method, this method must be match with the vertx-error.yml
prefix: E<code>
as
message key
If you want to change HttpStatusCode, you could overwrite getStatus()
as following:
public HttpStatusCode getStatus() {
// Default exception for 400
return HttpStatusCode.BAD_REQUEST;
}
Then in your code, write following code:
@Address("ZERO://USER")
public Envelop reply(final Envelop message) {
final User user = message.data(User.class);
final WebException error = new TestRequestException(getClass(),
"Lang", "Detail");
return Envelop.failure(error);
}
You'll see following error response:
{
"brief": "Bad Request",
"status": 400,
"code": -100001,
"message": "[ERR-100001] (UserWorker) ZeroException occurs: User defined Error Lang, details = Detail."
}
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )