-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from FoundryAI/feature/more-errors
Adds Conflict Error (409)
- Loading branch information
Showing
13 changed files
with
139 additions
and
76 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,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 | ||
} | ||
} |
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/authenticationError.spec.ts → test/authenticationError.spec.ts
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
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 |
---|---|---|
@@ -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); } | ||
} |
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
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
--require source-map-support/register | ||
--full-trace | ||
--bail | ||
src/**/*.spec.ts | ||
test/**/*.spec.ts |
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
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 |
---|---|---|
|
@@ -21,6 +21,6 @@ | |
"exclude": [ | ||
"dist", | ||
"node_modules", | ||
"test/**/*.spec.ts" | ||
"test/**/*.ts" | ||
] | ||
} | ||
} |