@@ -86,39 +86,34 @@ export default class BaseService {
86
86
87
87
$submit < T = any , F = any > ( method : Method , param ?: string | number , form ?: F , config ?: AxiosRequestConfig ) {
88
88
this . beforeSubmit ( )
89
+ const formData = hasFiles ( form ) ? objectToFormData ( form ) : form
90
+ const endpointPath = param ? `/${ this . endpoint } /${ param } ` : `/${ this . endpoint } `
91
+ const endpoint = endpointPath . replace ( / \/ \/ / g, '/' )
92
+ const url = this . __getParameterString ( endpoint )
93
+ const axiosConfig = { url, data : formData , method, ...config }
89
94
return new Promise < AxiosResponse < AxiosResponse < T > > > ( ( resolve , reject ) => {
90
- const formData = hasFiles ( form ) ? objectToFormData ( form ) : form
91
- const endpointPath = param ? `/${ this . endpoint } /${ param } ` : `/${ this . endpoint } `
92
- const endpoint = endpointPath . replace ( / \/ \/ / g, '/' )
93
- const url = this . __getParameterString ( endpoint )
94
- const axiosConfig = { url, data : formData , method, ...config }
95
- this . $http ( axiosConfig )
95
+ this . $http < T > ( axiosConfig )
96
96
. then ( ( response ) => {
97
97
this . onSuccess ( )
98
+ if ( this . $resetParameter ) this . removeParameters ( )
98
99
resolve ( response )
99
100
} )
100
101
. catch ( ( error : AxiosError < AxiosResponseData > ) => {
101
102
this . errors . processing = false
102
103
validator . processing = false
103
- const { response } = error
104
- if ( response && response . status === UNPROCESSABLE_ENTITY ) {
105
- const { data } = response
104
+ if ( error . response && error . response . status === UNPROCESSABLE_ENTITY ) {
106
105
const validationErrors : SimpleObject < any > = { }
107
- Object . assign ( validationErrors , data [ this . $errorProperty ] )
106
+ Object . assign ( validationErrors , error . response . data [ this . $errorProperty ] )
108
107
this . onFail ( validationErrors )
109
108
}
110
109
reject ( error )
111
110
} )
112
- if ( this . $resetParameter ) this . removeParameters ( )
113
111
} )
114
112
}
115
113
116
- submit < T = any , F = any > ( method : Method , url ?: string | number , form ?: F , config ?: AxiosRequestConfig ) {
117
- return new Promise < AxiosResponse < T > > ( ( resolve , reject ) => {
118
- this . $submit < T > ( method , url , form , config )
119
- . then ( ( { data } ) => resolve ( data ) )
120
- . catch ( ( err ) => reject ( err ) )
121
- } )
114
+ async submit < T = any , F = any > ( method : Method , url ?: string | number , form ?: F , config ?: AxiosRequestConfig ) {
115
+ const { data } = await this . $submit < T > ( method , url , form , config )
116
+ return data
122
117
}
123
118
124
119
private __getParameterString ( url : string ) {
0 commit comments