Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,26 @@ dist/

# Mac
.DS_Store

# JetBrains
.idea/

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
132 changes: 66 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
{
"name": "@foundry-ai/api-errors",
"version": "0.1.1",
"description": "Common errors that can be thrown and caught reliably across services",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/FoundryAI/api-errors.git"
},
"homepage": "https://github.com/FoundryAI/api-errors#readme",
"keywords": [
"foundry",
"foundryai",
"foundry-api",
"foundryai-api",
"error",
"errors"
"name": "@foundry-ai/api-errors",
"version": "0.1.1",
"description": "Common errors that can be thrown and caught reliably across services",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/FoundryAI/api-errors.git"
},
"homepage": "https://github.com/FoundryAI/api-errors#readme",
"keywords": [
"foundry",
"foundryai",
"foundry-api",
"foundryai-api",
"error",
"errors"
],
"author": "FoundryAI Engineering",
"license": "MIT",
"bugs": {
"url": "https://github.com/FoundryAI/api-errors/issues"
},
"scripts": {
"build": "tsc -p ./",
"prepublishOnly": "tsc -p ./",
"reportCoverage": "nyc report --reporter=text-lcov | coveralls",
"run": "ts-node ./src/index.ts",
"test": "nyc mocha",
"watch": "mocha-typescript-watch"
},
"devDependencies": {
"@types/chai": "^4.0.1",
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.19",
"chai": "^4.1.0",
"coveralls": "^2.13.1",
"mocha": "^3.5.0",
"mocha-typescript": "^1.1.7",
"nyc": "^11.1.0",
"source-map-support": "^0.4.15",
"supertest": "^3.0.0",
"ts-node": "^3.3.0",
"tslint": "^5.5.0",
"tslint-config-airbnb": "^5.2.1",
"typescript": "^2.4.2",
"typings": "^2.1.1"
},
"dependencies": {},
"nyc": {
"include": [
"src/**/*.ts"
],
"author": "FoundryAI Engineering",
"license": "MIT",
"bugs": {
"url": "https://github.com/FoundryAI/api-errors/issues"
},
"scripts": {
"build": "tsc -p ./",
"prepublishOnly": "tsc -p ./",
"reportCoverage": "nyc report --reporter=text-lcov | coveralls",
"run": "ts-node ./src/index.ts",
"test": "nyc mocha",
"watch": "mocha-typescript-watch"
},
"devDependencies": {
"@types/chai": "^4.0.1",
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.19",
"chai": "^4.1.0",
"coveralls": "^2.13.1",
"mocha": "^3.5.0",
"mocha-typescript": "^1.1.7",
"nyc": "^11.1.0",
"source-map-support": "^0.4.15",
"supertest": "^3.0.0",
"ts-node": "^3.3.0",
"tslint": "^5.5.0",
"tslint-config-airbnb": "^5.2.1",
"typescript": "^2.4.2",
"typings": "^2.1.1"
},
"dependencies": {},
"nyc": {
"include": [
"src/**/*.ts"
],
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"reporter": [
"lcov",
"text-summary"
],
"sourceMap": true,
"instrument": true
}
}
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"reporter": [
"lcov",
"text-summary"
],
"sourceMap": true,
"instrument": true
}
}
14 changes: 14 additions & 0 deletions src/conflictError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BaseError } from './baseError';

export class ConflictError extends BaseError {
constructor(message: string = 'Conflict', status: number = 409) {
// Calling parent constructor of base Error class.
super(message, status, 'conflict_error');

// Capturing stack trace, excluding constructor call from it.
Error.captureStackTrace(this, this.constructor);

// Saving class name in the property of our custom error as a shortcut.
this.name = this.constructor.name;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { AuthenticationError } from './authenticationError';
import { AuthenticationError } from '../src/authenticationError';

@suite class AuthenticationErrorDefaults {
public error: AuthenticationError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { BadRequestError } from './badRequestError';
import { BadRequestError } from '../src/badRequestError';

@suite class BadRequestErrorDefaults {
public error: BadRequestError;
Expand Down
2 changes: 1 addition & 1 deletion src/baseError.spec.ts → test/baseError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { BaseError } from './baseError';
import { BaseError } from '../src/baseError';

@suite class BaseErrorDefaults {
public error: BaseError;
Expand Down
26 changes: 26 additions & 0 deletions test/conflictError.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { ConflictError } from '../src/conflictError';

@suite class ConflictErrorDefaults {
public error: ConflictError;

before() { this.error = new ConflictError(); }

@test name() { expect(this.error.name).to.equal('ConflictError'); }
@test type() { expect(this.error.type).to.equal('conflict_error'); }
@test message() { expect(this.error.message).to.equal('Conflict'); }
@test status() { expect(this.error.status).to.equal(409); }
}

@suite class ConflictErrorCustom {
public error: ConflictError;

before() { this.error = new ConflictError('custom message', 999); }

@test name() { expect(this.error.name).to.equal('ConflictError'); }
@test type() { expect(this.error.type).to.equal('conflict_error'); }
@test message() { expect(this.error.message).to.equal('custom message'); }
@test status() { expect(this.error.status).to.equal(999); }
}
2 changes: 1 addition & 1 deletion src/forbiddenError.spec.ts → test/forbiddenError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { ForbiddenError } from './forbiddenError';
import { ForbiddenError } from '../src/forbiddenError';

@suite class ForbiddenErrorDefaults {
public error: ForbiddenError;
Expand Down
2 changes: 1 addition & 1 deletion src/internalError.spec.ts → test/internalError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { InternalError } from './internalError';
import { InternalError } from '../src/internalError';

@suite class InternalErrorDefaults {
public error: InternalError;
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
--require source-map-support/register
--full-trace
--bail
src/**/*.spec.ts
test/**/*.spec.ts
2 changes: 1 addition & 1 deletion src/notFoundError.spec.ts → test/notFoundError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { NotFoundError } from './notFoundError';
import { NotFoundError } from '../src/notFoundError';

@suite class NotFoundErrorDefaults {
public error: NotFoundError;
Expand Down
2 changes: 1 addition & 1 deletion src/rateLimitError.spec.ts → test/rateLimitError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { expect } from 'chai';

import { RateLimitError } from './rateLimitError';
import { RateLimitError } from '../src/rateLimitError';

@suite class RateLimitErrorDefaults {
public error: RateLimitError;
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"exclude": [
"dist",
"node_modules",
"test/**/*.spec.ts"
"test/**/*.ts"
]
}
}