Started adding create method to service
All checks were successful
the build was successful

This commit is contained in:
kolaente 2019-02-21 08:25:44 +01:00
parent adc795943d
commit 6f92b5234b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B

View File

@ -3,6 +3,8 @@ import {reduce, replace} from 'lodash'
let config = require('../../public/config.json')
// TODO: Reject requests if they don't have route set
export default class AbstractService {
/////////////////////////////
@ -54,11 +56,10 @@ export default class AbstractService {
/**
* Handles the error and rejects the promise.
* @param url
* @param error
* @returns {Promise<never>}
*/
errorHandler(url, error) {
errorHandler(error) {
return Promise.reject(error)
}
@ -141,7 +142,23 @@ export default class AbstractService {
// Finally make the request and get our data.
return this.http.get(this.getReplacedRoute(this.paths.get, pathparams), {params: params})
.catch(error => {
return this.errorHandler(this.paths.get, error)
return this.errorHandler(error)
})
.then(response => {
return Promise.resolve(response.data)
})
.finally(() => {
cancel()
})
}
createData(pathparams, data) {
const cancel = this.setLoading()
// Finally make the request and get our data.
return this.http.put(this.getReplacedRoute(this.paths.create, pathparams), data)
.catch(error => {
return this.errorHandler(error)
})
.then(response => {
return Promise.resolve(response.data)