gpt4 book ai didi

javascript - abort() 不更改 header

转载 作者:行者123 更新时间:2023-12-03 06:33:55 25 4
gpt4 key购买 nike

所以这是一个位于 DB::transaction() block 内的中止调用:

 abort(422, 'insufficient_credits', ['statusText' => 'insufficient_credits']);

不幸的是,它不会修改响应的实际 header 。相反,它似乎是在某些嵌套范围内创建 header ...不太确定如何访问它:

Response Image

进行调用的 JavaScript 文件:

this.$http.post('/api/test', data).then(function(response) {
//Stuff here
}, function(response) {
if(response.status === 422) {
//This triggers the output in the screenshot above
console.log(response);
}});

如何修改我的代码/中止错误,以便它实际修改 header 值?如果这是不可能的,是否有任何方法可以回传并检索响应状态旁边的附加信息?

最佳答案

不要使用 abort(),而是使用 Symfonys Response 类(或相应的 Laravel 帮助器,如我在示例中所做的那样)来获取自定义响应:

return response($yourContent, $statusCode)
->header('Content-Type', $type)
->header('X-Header-One', 'Header Value')
->header('X-Header-Two', 'Header Value');

关于javascript - abort() 不更改 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38319349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com