Skip to content

Commit

Permalink
fix: Fix the request reject params in the repo of verify access
Browse files Browse the repository at this point in the history
Signed-off-by: harrisonliu5 <harrisonliu_5@163.com>
  • Loading branch information
harrisonliu5 committed Aug 13, 2020
1 parent f041be4 commit 98aaf31
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 47 deletions.
76 changes: 31 additions & 45 deletions src/stores/devops/scm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { action, observable, toJS } from 'mobx'
import { isArray, get, isEmpty, set } from 'lodash'
import { parseUrl, safeParseJSON, getQueryString, generateId } from 'utils'
import { parseUrl, getQueryString, generateId } from 'utils'
import { CREDENTIAL_DISPLAY_KEY } from 'utils/constants'

import BaseStore from 'stores/devops/base'
Expand All @@ -30,58 +30,43 @@ export default class SCMStore extends BaseStore {

this.verifyAccessErrorHandle = {
github: (resp, error) => {
if (!isEmpty(get(error, 'message'))) {
const err = safeParseJSON(error.message)
if (err.code === 428) {
this.isAccessTokenWrong = true
this.orgList.isLoading = false
return
}
if (window.onunhandledrejection) {
err.status = error.status
err.reason = error.reason
window.onunhandledrejection(err)
}
return Promise.reject(error)
if (error.code === 428) {
this.isAccessTokenWrong = true
this.orgList.isLoading = false
return
}
if (window.onunhandledrejection) {
window.onunhandledrejection(error)
}
return Promise.reject(error)
},
'bitbucket-server': (resp, error) => {
if (!isEmpty(get(error, 'message'))) {
const err = safeParseJSON(error.message)

if (err.code === 428) {
this.creatBitBucketServersError = {
password: {
message: t('Wrong username or password, please try again'),
},
}
return
}

if (isArray(err.errors) && !isEmpty(err.errors)) {
this.creatBitBucketServersError = err.errors.reduce(
(prev, errorItem) => {
prev[errorItem.field] = { message: errorItem.message }
return prev
},
{}
)
return
if (error.code === 428) {
this.creatBitBucketServersError = {
password: {
message: t('Wrong username or password, please try again'),
},
}
return
}

this.creatBitBucketServersError = { all: err.message }

if (window.onunhandledrejection) {
err.status = error.status
err.reason = error.reason
window.onunhandledrejection(err)
}
return Promise.reject(error)
if (isArray(error.errors) && !isEmpty(error.errors)) {
this.creatBitBucketServersError = error.errors.reduce(
(prev, errorItem) => {
prev[errorItem.field] = { message: errorItem.message }
return prev
},
{}
)
return
}

this.creatBitBucketServersError = { all: error.message }

if (window.onunhandledrejection) {
window.onunhandledrejection(resp)
window.onunhandledrejection(error)
}

return Promise.reject(error)
},
}
Expand Down Expand Up @@ -210,7 +195,7 @@ export default class SCMStore extends BaseStore {
})

if (result && result.credentialId) {
this.githubCredentialId = `github-${token.slice(0, 6)}`
this.githubCredentialId = `github-${token.slice(0, 6)}-${generateId(5)}`

const data = {
id: this.githubCredentialId,
Expand Down Expand Up @@ -357,6 +342,7 @@ export default class SCMStore extends BaseStore {
this.githubCredentialId = ''
this.formData = {}
this.tokenFormData = {}
this.creatBitBucketServersError = {}
}

@action
Expand Down
2 changes: 1 addition & 1 deletion src/stores/notification/mailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class AddressStore extends Base {
`${this.getMailServiceV2URL(cluster)}/validation`,
params,
{},
error => {
(resp, error) => {
window.onunhandledrejection(error)
return {
is_succ: false,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ function handleResponse(response, reject) {
// some errors are the string-json in devops
const errBody = safeParseJSON(text)
if (isObject(errBody) && !isEmpty(errBody)) {
error.status = errBody.code
error.status = response.status
error.code = errBody.code
error.message = errBody.message
error.errors = errBody.errors
}

if (typeof reject === 'function') {
Expand Down

0 comments on commit 98aaf31

Please sign in to comment.