Skip to content

Commit

Permalink
Merge pull request #16 from snyk-tech-services/develop
Browse files Browse the repository at this point in the history
fix: deploy error fix
  • Loading branch information
aarlaud committed Jun 15, 2020
2 parents d587120 + 6308ab2 commit ddacb19
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ If not defining custom channel name, default channel name is used in the backend
Above will only show result of call to `/` as listener is only for 'test-channel'


### Customize token and or snyk token
### Customize queue/retry values and or snyk token
While instantiating your manager

#### Customize queue size and intervals
Expand All @@ -160,4 +160,4 @@ const requestManager = new requestsManager({snykToken:'21346-1234-1234-1234')
#### Customize snyk token and queue|intervals|retries
```
const requestManager = new requestsManager({snykToken:'21346-1234-1234-1234', burstSize: 20, period: 100, maxRetryCount: 10})
```
```
8 changes: 8 additions & 0 deletions src/lib/customErrors/apiError.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@


class ApiError extends Error {
data: {}
constructor(message: any){
super(message)
this.name = "ApiError"
this.message = (message || "")
this.data = (message.response?.data || "")
}
}

class ApiAuthenticationError extends Error {
data: {}
constructor(message: any){
super(message)
this.name = "ApiAuthenticationError"
this.message = (message || "")
this.data = (message.response?.data || "")
}
}

class NotFoundError extends Error {
data: {}
constructor(message: any){
super(message)
this.name = "NotFoundError"
this.message = (message || "")
this.data = (message.response?.data || "")
}
}

class GenericError extends Error {
data: {}
constructor(message: any){
super(message)
this.name = "Unknown"
this.message = (message || "")
this.data = (message.response?.data || "")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const makeSnykRequest = async (request: snykRequest, snykToken: string = '') =>
case 401:
throw new Error.ApiAuthenticationError(err)
case 404:
throw new Error.NotFoundError("Snyk API - Could not find this resource")
throw new Error.NotFoundError(err)
case 500:
throw new Error.ApiError(err)
default:
Expand Down
8 changes: 8 additions & 0 deletions test/lib/request/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('Test Snyk Utils error handling/classification', () => {
try {
await makeSnykRequest({ verb: 'GET', url: '/xyz', body: '' });
} catch (err) {
expect(err.data).toEqual(404);
expect(err).toBeInstanceOf(NotFoundError);
}
});
Expand All @@ -111,6 +112,7 @@ describe('Test Snyk Utils error handling/classification', () => {
body: JSON.stringify(bodyToSend),
});
} catch (err) {
expect(err.data).toEqual(404);
expect(err).toBeInstanceOf(NotFoundError);
}
});
Expand All @@ -119,6 +121,7 @@ describe('Test Snyk Utils error handling/classification', () => {
try {
await makeSnykRequest({ verb: 'GET', url: '/apierror' });
} catch (err) {
expect(err.data).toEqual(500);
expect(err).toBeInstanceOf(ApiError);
}
});
Expand All @@ -133,6 +136,7 @@ describe('Test Snyk Utils error handling/classification', () => {
body: JSON.stringify(bodyToSend),
});
} catch (err) {
expect(err.data).toEqual(500);
expect(err).toBeInstanceOf(ApiError);
}
});
Expand All @@ -141,6 +145,7 @@ describe('Test Snyk Utils error handling/classification', () => {
try {
await makeSnykRequest({ verb: 'GET', url: '/apiautherror' });
} catch (err) {
expect(err.data).toEqual(401);
expect(err).toBeInstanceOf(ApiAuthenticationError);
}
});
Expand All @@ -155,6 +160,7 @@ describe('Test Snyk Utils error handling/classification', () => {
body: JSON.stringify(bodyToSend),
});
} catch (err) {
expect(err.data).toEqual(401);
expect(err).toBeInstanceOf(ApiAuthenticationError);
}
});
Expand All @@ -163,6 +169,7 @@ describe('Test Snyk Utils error handling/classification', () => {
try {
await makeSnykRequest({ verb: 'GET', url: '/genericerror' });
} catch (err) {
expect(err.data).toEqual(512);
expect(err).toBeInstanceOf(GenericError);
}
});
Expand All @@ -177,6 +184,7 @@ describe('Test Snyk Utils error handling/classification', () => {
body: JSON.stringify(bodyToSend),
});
} catch (err) {
expect(err.data).toEqual(512);
expect(err).toBeInstanceOf(GenericError);
}
});
Expand Down

0 comments on commit ddacb19

Please sign in to comment.