Skip to content

Commit fc883fe

Browse files
Merge pull request #2 from Imagination-Media/feature/IMIN-221
[IMIN-221] Throw errors instead of logging them
2 parents 7399725 + 8df0050 commit fc883fe

File tree

3 files changed

+28
-44
lines changed

3 files changed

+28
-44
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@imagination-media/magento-api-rest",
3-
"version": "3.0.9",
3+
"version": "3.0.10",
44
"description": "Magento API wrapper",
55
"main": "lib/index.js",
66
"files": [

src/index.ts

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,20 @@ class MagentoApi {
101101
* @returns Promise<any>
102102
*/
103103
async get(path: string, data: any | null = null): Promise<any> {
104-
try {
105-
let url = `${this.getUrl()}${path}`
106-
107-
if (data) {
108-
let params = {
109-
searchCriteria: data
110-
}
111-
url += `?${this.parseQueryString(params)}`
112-
return await axios.get(url, {
113-
headers: this.getHeaders(url, "GET") as any,
114-
})
115-
} else {
116-
return await axios.get(`${this.getUrl()}${path}`, {
117-
headers: this.getHeaders(url, "GET") as any
118-
})
104+
let url = `${this.getUrl()}${path}`
105+
106+
if (data) {
107+
let params = {
108+
searchCriteria: data
119109
}
120-
} catch (error: any) {
121-
console.error(error)
110+
url += `?${this.parseQueryString(params)}`
111+
return await axios.get(url, {
112+
headers: this.getHeaders(url, "GET") as any,
113+
})
114+
} else {
115+
return await axios.get(`${this.getUrl()}${path}`, {
116+
headers: this.getHeaders(url, "GET") as any
117+
})
122118
}
123119
}
124120

@@ -129,14 +125,10 @@ class MagentoApi {
129125
* @returns Promise<any>
130126
*/
131127
async post(path: string, data: any): Promise<any> {
132-
try {
133-
const url = `${this.getUrl()}${path}`
134-
return await axios.post(url, data, {
135-
headers: this.getHeaders(url, "POST") as any
136-
})
137-
} catch (error: any) {
138-
console.error(error)
139-
}
128+
const url = `${this.getUrl()}${path}`
129+
return await axios.post(url, data, {
130+
headers: this.getHeaders(url, "POST") as any
131+
})
140132
}
141133

142134
/**
@@ -146,14 +138,10 @@ class MagentoApi {
146138
* @returns Promise<any>
147139
*/
148140
async put(path: string, data: any): Promise<any> {
149-
try {
150-
const url = `${this.getUrl()}${path}`
151-
return await axios.put(url, data, {
152-
headers: this.getHeaders(url, "PUT") as any
153-
})
154-
} catch (error: any) {
155-
console.error(error)
156-
}
141+
const url = `${this.getUrl()}${path}`
142+
return await axios.put(url, data, {
143+
headers: this.getHeaders(url, "PUT") as any
144+
})
157145
}
158146

159147
/**
@@ -162,14 +150,10 @@ class MagentoApi {
162150
* @returns Promise<any>
163151
*/
164152
async delete(path: string): Promise<any> {
165-
try {
166-
const url = `${this.getUrl()}${path}`
167-
return await axios.delete(url, {
168-
headers: this.getHeaders(url, "DELETE") as any
169-
})
170-
} catch (error: any) {
171-
console.error(error)
172-
}
153+
const url = `${this.getUrl()}${path}`
154+
return await axios.delete(url, {
155+
headers: this.getHeaders(url, "DELETE") as any
156+
})
173157
}
174158

175159
/**

0 commit comments

Comments
 (0)