mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-10 20:59:55 +00:00
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:
commit
a916f69c58
@ -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';
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user