Skip to content

Commit

Permalink
fix($Axios): check nullity before validation
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Feb 10, 2020
1 parent beea982 commit ac6a2a6
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/plugins/axios/axios-for-intra-communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ export const service = Axios.create({
// 2. Request interceptor's configuration.
service.interceptors.request.use(
async (axiosRequestConfig: AxiosRequestConfig) => {
let validation = await validate(axiosRequestConfig?.params)
if (validation.length > 0) {
console.error('Validation failed! Validation:', validation)
console.error('Validation failed! Error message:', ClassValidationUtil.getAllValidationError(validation))
throw new Error(`Validation failed! The 1st error: ${ClassValidationUtil.getFirstValidationError(validation)}`)
if (axiosRequestConfig?.params) {
const validation = await validate(axiosRequestConfig.params)
if (validation.length > 0) {
console.error('Params validation failed! Validation:', validation)
console.error('Params validation failed! Error message:', ClassValidationUtil.getAllValidationError(validation))
throw new Error(`Params validation failed! The 1st error: ${ClassValidationUtil.getFirstValidationError(validation)}`)
}
}
validation = await validate(axiosRequestConfig?.data)
if (validation.length > 0) {
console.error('Validation failed! Validation:', validation)
console.error('Validation failed! Error message:', ClassValidationUtil.getAllValidationError(validation))
throw new Error(`Validation failed! The 1st error: ${ClassValidationUtil.getFirstValidationError(validation)}`)
if (axiosRequestConfig?.data) {
const validation = await validate(axiosRequestConfig.data)
if (validation.length > 0) {
console.error('Data validation failed! Validation:', validation)
console.error('Data validation failed! Error message:', ClassValidationUtil.getAllValidationError(validation))
throw new Error(`Data validation failed! The 1st error: ${ClassValidationUtil.getFirstValidationError(validation)}`)
}
}
// Cancel and remove same request before sending upcoming request.
// Cancellation.cancelAndRemoveSamePendingRequest(axiosRequestConfig)
Expand Down

0 comments on commit ac6a2a6

Please sign in to comment.