Move everything to models and services #17
|
@ -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)
|
||||
|
|
Reference in New Issue
Block a user