-
Notifications
You must be signed in to change notification settings - Fork 1
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 vultuk/error-handling
Error handling
- Loading branch information
Showing
16 changed files
with
253 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class BadRequestError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Invalid Input"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 400; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "An input was expected but it was not there. Therefore we could not perform the API request."; | ||
|
||
} |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class ForbiddenError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Forbidden"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 403; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "You do not have the required permissions to access the requested resource."; | ||
|
||
} |
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,9 @@ | ||
export { BadRequestError } from "./badRequest"; | ||
export { ForbiddenError } from "./forbidden"; | ||
export { InternalServerError } from "./internalServerError"; | ||
export { NotAcceptableError } from "./notAcceptable"; | ||
export { NotAllowedError } from "./notAllowed"; | ||
export { NotFoundError } from "./notFound"; | ||
export { TooManyRequestsError } from "./tooManyRequests"; | ||
export { UnauthorisedError } from "./unauthorised"; | ||
export { UnavailableError } from "./unavailable"; |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class InternalServerError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Internal Server Error"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 500; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "An error has occurred in either Tide's service or the Node-Tide module. Please inspect this error further for full details."; | ||
|
||
} |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class NotAcceptableError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Not Acceptable"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 406; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "You requested a format that isn’t JSON."; | ||
|
||
} |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class NotAllowedError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Not Allowed"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 405; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "You tried to access a resource with an invalid method."; | ||
|
||
} |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class NotFoundError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Not Found"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 404; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "The requested resource was not found."; | ||
|
||
} |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class TooManyRequestsError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Too Many Requests"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 429; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "There have been too many requests to this resource this hour, please ensure you stay within appropriate rate limiting."; | ||
|
||
} |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class UnauthorisedError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Unauthorised"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 401; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "It has not been possible to access the Tide API as no valid access token was provided."; | ||
|
||
} |
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,20 @@ | ||
import * as Interfaces from "../interfaces"; | ||
|
||
export class UnavailableError extends Error implements Interfaces.ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string = "Unavailable"; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number = 503; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string = "Tide's API service is currently undergoing maintainance. Please try again later."; | ||
|
||
} |
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,18 @@ | ||
export interface ErrorMessage { | ||
|
||
/** | ||
* Holds a basic message about this error | ||
*/ | ||
message: string; | ||
|
||
/** | ||
* Holds the HTTP error code associated with the error | ||
*/ | ||
httpErrorCode: number; | ||
|
||
/** | ||
* Holds a more desciptive message about the error | ||
*/ | ||
description: string; | ||
|
||
} |
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