Playframwork 2.x 尝试生成自定义 400 响应
Playframwork 2.x trying to generate custom 400 response
正在尝试生成自定义 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
}
}
希望这对您有所帮助:
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
}
}
给你,
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
正在尝试生成自定义 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
}
}
希望这对您有所帮助:
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
}
}
给你,
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