-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from snyk-tech-services/develop
Release: reduce open file handles
- Loading branch information
Showing
11 changed files
with
561 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,41 @@ | ||
|
||
|
||
class ApiError extends Error { | ||
data: {} | ||
constructor(message: any){ | ||
super(message) | ||
this.name = "ApiError" | ||
this.message = (message || "") | ||
this.data = (message.response?.data || "") | ||
} | ||
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 || "") | ||
} | ||
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 || "") | ||
} | ||
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 || "") | ||
} | ||
data: {}; | ||
constructor(message: any) { | ||
super(message); | ||
this.name = 'Unknown'; | ||
this.message = message || ''; | ||
this.data = message.response?.data || ''; | ||
} | ||
} | ||
|
||
export { | ||
ApiError, | ||
ApiAuthenticationError, | ||
NotFoundError, | ||
GenericError | ||
} | ||
export { ApiError, ApiAuthenticationError, NotFoundError, GenericError }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
|
||
|
||
class BadInputError extends Error { | ||
constructor(message: any){ | ||
super(message) | ||
this.name = "BadInputError" | ||
this.message = (message || "") | ||
} | ||
constructor(message: any) { | ||
super(message); | ||
this.name = 'BadInputError'; | ||
this.message = message || ''; | ||
} | ||
} | ||
|
||
export { | ||
BadInputError | ||
} | ||
export { BadInputError }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,89 @@ | ||
import * as debugModule from 'debug'; | ||
|
||
import {ApiError, | ||
ApiAuthenticationError, | ||
NotFoundError, | ||
GenericError | ||
} from './apiError' | ||
const debug = debugModule('snyk') | ||
|
||
const requestsManagerErrorOverload = (err: Error, channel: string, requestId: string): Error => { | ||
debug('ERROR:', err); | ||
switch(err?.name){ | ||
case 'ApiError': | ||
return new RequestsManagerApiError(err.message, channel, requestId) | ||
case 'ApiAuthenticationError': | ||
return new RequestsManagerApiAuthenticationError(err.message, channel, requestId) | ||
case 'NotFoundError': | ||
return new RequestsManagerNotFoundError(err.message, channel, requestId) | ||
case 'Unknown': | ||
return new RequestsManagerGenericError(err.message, channel, requestId) | ||
default: | ||
} return new RequestsManagerGenericError("Unclassified", channel, requestId) | ||
} | ||
import { | ||
ApiError, | ||
ApiAuthenticationError, | ||
NotFoundError, | ||
GenericError, | ||
} from './apiError'; | ||
const debug = debugModule('snyk'); | ||
|
||
class RequestsManagerApiError extends ApiError { | ||
channel: string | ||
requestId: string | ||
constructor(message: any, channel: string, requestId: string){ | ||
super(message) | ||
this.name = "ApiError" | ||
this.channel = channel | ||
this.requestId = requestId | ||
this.message = (message || "") | ||
} | ||
channel: string; | ||
requestId: string; | ||
constructor(message: string, channel: string, requestId: string) { | ||
super(message); | ||
this.name = 'ApiError'; | ||
this.channel = channel; | ||
this.requestId = requestId; | ||
this.message = message || ''; | ||
} | ||
} | ||
|
||
class RequestsManagerApiAuthenticationError extends ApiAuthenticationError { | ||
channel: string | ||
requestId: string | ||
constructor(message: any, channel: string, requestId: string){ | ||
super(message) | ||
this.name = "ApiAuthenticationError" | ||
this.channel = channel | ||
this.requestId = requestId | ||
this.message = (message || "") | ||
} | ||
channel: string; | ||
requestId: string; | ||
constructor(message: string, channel: string, requestId: string) { | ||
super(message); | ||
this.name = 'ApiAuthenticationError'; | ||
this.channel = channel; | ||
this.requestId = requestId; | ||
this.message = message || ''; | ||
} | ||
} | ||
|
||
class RequestsManagerNotFoundError extends NotFoundError { | ||
channel: string | ||
requestId: string | ||
constructor(message: any, channel: string, requestId: string){ | ||
super(message) | ||
this.name = "NotFoundError" | ||
this.channel = channel | ||
this.requestId = requestId | ||
this.message = (message || "") | ||
} | ||
channel: string; | ||
requestId: string; | ||
constructor(message: string, channel: string, requestId: string) { | ||
super(message); | ||
this.name = 'NotFoundError'; | ||
this.channel = channel; | ||
this.requestId = requestId; | ||
this.message = message || ''; | ||
} | ||
} | ||
|
||
class RequestsManagerGenericError extends GenericError { | ||
channel: string | ||
requestId: string | ||
constructor(message: any, channel: string, requestId: string){ | ||
super(message) | ||
this.name = "Unknown" | ||
this.channel = channel | ||
this.requestId = requestId | ||
this.message = (message || "") | ||
} | ||
channel: string; | ||
requestId: string; | ||
constructor(message: string, channel: string, requestId: string) { | ||
super(message); | ||
this.name = 'Unknown'; | ||
this.channel = channel; | ||
this.requestId = requestId; | ||
this.message = message || ''; | ||
} | ||
} | ||
|
||
const requestsManagerErrorOverload = ( | ||
err: Error, | ||
channel: string, | ||
requestId: string, | ||
): Error => { | ||
debug('ERROR:', err); | ||
switch (err?.name) { | ||
case 'ApiError': | ||
return new RequestsManagerApiError(err.message, channel, requestId); | ||
case 'ApiAuthenticationError': | ||
return new RequestsManagerApiAuthenticationError( | ||
err.message, | ||
channel, | ||
requestId, | ||
); | ||
case 'NotFoundError': | ||
return new RequestsManagerNotFoundError(err.message, channel, requestId); | ||
case 'Unknown': | ||
return new RequestsManagerGenericError(err.message, channel, requestId); | ||
default: | ||
} | ||
return new RequestsManagerGenericError('Unclassified', channel, requestId); | ||
}; | ||
|
||
export { | ||
RequestsManagerApiError, | ||
RequestsManagerApiAuthenticationError, | ||
RequestsManagerNotFoundError, | ||
RequestsManagerGenericError, | ||
requestsManagerErrorOverload | ||
} | ||
RequestsManagerApiError, | ||
RequestsManagerApiAuthenticationError, | ||
RequestsManagerNotFoundError, | ||
RequestsManagerGenericError, | ||
requestsManagerErrorOverload, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
import * as chalk from 'chalk' | ||
import * as chalk from 'chalk'; | ||
import debugModule = require('debug'); | ||
|
||
const handleError = (error: Error): void => { | ||
const debug = debugModule('snyk'); | ||
if (!process.env.DEBUG) { | ||
console.log(chalk.hex('#316fcc')('hint: Check debug mode -d')); | ||
} | ||
switch (error.name) { | ||
case 'ApiError': | ||
console.log('Uh oh, seems like we messed something up?'); | ||
debug(error); | ||
break; | ||
case 'ApiAuthenticationError': | ||
console.log('Hum, looks like we have a wrong token?'); | ||
debug(error); | ||
break; | ||
case 'NotFoundError': | ||
console.log("Couldn't find find this resource"); | ||
debug(error); | ||
break; | ||
case 'BadInputError': | ||
console.log('Bad input. Please check the --help'); | ||
debug(error); | ||
break; | ||
default: | ||
//console.log("Unknown error") | ||
debug(error); | ||
} | ||
}; | ||
|
||
const handleError = (error: Error) => { | ||
const debug = debugModule('snyk') | ||
if(!process.env.DEBUG) { | ||
console.log(chalk.hex("#316fcc")("hint: Check debug mode -d")) | ||
} | ||
switch(error.name){ | ||
case 'ApiError': | ||
console.log("Uh oh, seems like we messed something up?") | ||
debug(error) | ||
break; | ||
case 'ApiAuthenticationError': | ||
console.log("Hum, looks like we have a wrong token?") | ||
debug(error) | ||
break; | ||
case 'NotFoundError': | ||
console.log("Couldn't find find this resource") | ||
debug(error) | ||
break; | ||
case 'BadInputError': | ||
console.log("Bad input. Please check the --help") | ||
debug(error) | ||
break; | ||
default: | ||
//console.log("Unknown error") | ||
debug(error) | ||
} | ||
} | ||
|
||
export default handleError | ||
export default handleError; |
Oops, something went wrong.