Skip to content

Commit

Permalink
Merge pull request #2 from Imagination-Media/feature/IMIN-221
Browse files Browse the repository at this point in the history
[IMIN-221] Throw errors instead of logging them
  • Loading branch information
igor-imaginemage authored Jul 24, 2024
2 parents 7399725 + 8df0050 commit fc883fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 44 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@imagination-media/magento-api-rest",
"version": "3.0.9",
"version": "3.0.10",
"description": "Magento API wrapper",
"main": "lib/index.js",
"files": [
Expand Down
66 changes: 25 additions & 41 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,20 @@ class MagentoApi {
* @returns Promise<any>
*/
async get(path: string, data: any | null = null): Promise<any> {
try {
let url = `${this.getUrl()}${path}`

if (data) {
let params = {
searchCriteria: data
}
url += `?${this.parseQueryString(params)}`
return await axios.get(url, {
headers: this.getHeaders(url, "GET") as any,
})
} else {
return await axios.get(`${this.getUrl()}${path}`, {
headers: this.getHeaders(url, "GET") as any
})
let url = `${this.getUrl()}${path}`

if (data) {
let params = {
searchCriteria: data
}
} catch (error: any) {
console.error(error)
url += `?${this.parseQueryString(params)}`
return await axios.get(url, {
headers: this.getHeaders(url, "GET") as any,
})
} else {
return await axios.get(`${this.getUrl()}${path}`, {
headers: this.getHeaders(url, "GET") as any
})
}
}

Expand All @@ -129,14 +125,10 @@ class MagentoApi {
* @returns Promise<any>
*/
async post(path: string, data: any): Promise<any> {
try {
const url = `${this.getUrl()}${path}`
return await axios.post(url, data, {
headers: this.getHeaders(url, "POST") as any
})
} catch (error: any) {
console.error(error)
}
const url = `${this.getUrl()}${path}`
return await axios.post(url, data, {
headers: this.getHeaders(url, "POST") as any
})
}

/**
Expand All @@ -146,14 +138,10 @@ class MagentoApi {
* @returns Promise<any>
*/
async put(path: string, data: any): Promise<any> {
try {
const url = `${this.getUrl()}${path}`
return await axios.put(url, data, {
headers: this.getHeaders(url, "PUT") as any
})
} catch (error: any) {
console.error(error)
}
const url = `${this.getUrl()}${path}`
return await axios.put(url, data, {
headers: this.getHeaders(url, "PUT") as any
})
}

/**
Expand All @@ -162,14 +150,10 @@ class MagentoApi {
* @returns Promise<any>
*/
async delete(path: string): Promise<any> {
try {
const url = `${this.getUrl()}${path}`
return await axios.delete(url, {
headers: this.getHeaders(url, "DELETE") as any
})
} catch (error: any) {
console.error(error)
}
const url = `${this.getUrl()}${path}`
return await axios.delete(url, {
headers: this.getHeaders(url, "DELETE") as any
})
}

/**
Expand Down

0 comments on commit fc883fe

Please sign in to comment.