如果发生任何异常错误,则使用API,该API将使用vuej在Jira上自动创建票证

idfiyjo8  于 2023-02-05  发布在  Vue.js
关注(0)|答案(1)|浏览(126)

我已经通过post man点击了API,它在jira上创建了票证,但现在当我使用index.js并在vuejs中编写代码时,它显示了cors错误
我不明白的流程时,我生成一个演示错误,它显示什么都没有,除了cors错误

import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false;
import axios from 'axios';
Vue.config.errorHandler = function (err) {
  // Get the error details
  const errorMessage = err.message;
  const stackTrace = err.stack;
  console.log("error from vue event handler ===>", errorMessage, stackTrace);
  console.log(process.env)
  // Create the JIRA ticket
  const data = {
    fields: {
      project: {
        key: 'EE'
      },
      summary: errorMessage,
      description: stackTrace.toString(),
      issuetype: {
        id: '10004'
      }
    }
  };
  axios.post('https://errorgene.atlassian.net/rest/api/2/issue/', data, {
    auth: {
      username: 'syed.haider@voltro.com',
      password: 'iPUX7n9nk2VXyRBJOWysF202',
    },
    headers:{
      'X-Atlassian-Token':'no-check',
    }
  })
  .then(response => {
    console.log('JIRA ticket created successfully', response)
  })
  .catch(error => {
    console.error('Error creating JIRA ticket:', error)
  });
}
new Vue({
  render: h => h(App),
}).$mount('#app')
7fyelxc5

7fyelxc51#

先读这个:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Cors只在从浏览器发出请求时才起作用,所以你用vue做什么。当用postman发出请求时,它不是来自浏览器,因此没有科塞错误。
有两种方法可以修复atlassian api的这个问题。
1:使用oauth2进行身份验证atlassian支持此操作,并且不会给予您一个cors错误。
2:创建一个小节点API来请求atlassian api,这将使它成为服务器到服务器,所以cors不是问题。在创建了小节点api之后,你可以从vue向这个小节点api发出请求,它将工作。

相关问题