尝试生成自定义400响应。我不能为我的生活弄清楚如何在我的全局设置中发送204代替400响应。如果你帮助我,请告诉我。
由于
public class Global extends GlobalSettings {
@Override
public Promise<Result> onBadRequest(RequestHeader request, String error){
return status(204); //ideally but don't know what to put here
}
}
答案 0 :(得分:1)
你走了,
public class Global extends GlobalSettings {
@Override
public Promise<Result> onError(RequestHeader arg0, Throwable arg1) {
super.onError(arg0, arg1);
return F.Promise.promise(()->{return play.mvc.Results.noContent();});
}
@Override
public Promise<Result> onBadRequest(RequestHeader arg0, String arg1) {
super.onBadRequest(arg0, arg1);
return F.Promise.promise(()->{return play.mvc.Results.noContent();});
}
}
在你的application.conf
中# Define the Global object class for this application.
# Default to Global in the root package.
application.global=Global
答案 1 :(得分:0)
希望这会有所帮助:
public class Global extends GlobalSettings {
@Override
public play.mvc.Result onBadRequest(RequestHeader request, String error) {
return play.mvc.Results.noContent(); //Generates a 204 NO_CONTENT simple result
}
}