Merge pull request #745 from resin-io/improve-error-typings

lib/errors: Improve typings by extending Error class for predicates
This commit is contained in:
CameronDiver 2018-09-13 12:21:21 +01:00 committed by GitHub
commit a916f69c58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,15 +3,25 @@ import TypedError = require('typed-error');
import { checkInt } from './validation';
export function NotFoundError(err: { statusCode?: string }): boolean {
// To keep the bluebird typings happy, we need to accept
// an error, and in this case, it would also contain a status code
interface StatusCodeError extends Error {
statusCode?: string;
}
interface CodedSysError extends Error {
code?: string;
}
export function NotFoundError(err: StatusCodeError): boolean {
return checkInt(err.statusCode) === 404;
}
export function ENOENT(err: { code: string, [key: string]: any }): boolean {
export function ENOENT(err: CodedSysError): boolean {
return err.code === 'ENOENT';
}
export function EEXIST(err: { code: string, [key: string]: any }): boolean {
export function EEXIST(err: CodedSysError): boolean {
return err.code === 'EEXIST';
}