This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c850ff
commit 4b90cca
Showing
3 changed files
with
66 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,130 @@ | ||
import { Logger, LogLevel, LogEntry } from "../utils/logging"; | ||
import { Logger, LogLevel } from "../utils/logging"; | ||
|
||
/** | ||
* Base class for creating exceptions | ||
* | ||
*/ | ||
export abstract class Exception extends Error { | ||
/** | ||
* @param name The Name given to the Error instance | ||
* @param message The message contained by the Error instance | ||
* | ||
*/ | ||
constructor(name: string, message: string) { | ||
super(message); | ||
this.name = name; | ||
} | ||
|
||
protected getLogEntry(): Promise<LogEntry> { | ||
return Promise.resolve(<LogEntry>{ data: {}, level: LogLevel.Error, message: this.message }); | ||
} | ||
|
||
protected Log(): Promise<void> { | ||
return this.getLogEntry().then(e => Logger.log(e)); | ||
} | ||
function defaultLog(error: Error) { | ||
Logger.log({ data: {}, level: LogLevel.Error, message: `[${error.name}]::${error.message}` }); | ||
} | ||
|
||
/** | ||
* Represents an exception with an HttpClient request | ||
* | ||
*/ | ||
export class ProcessHttpClientResponseException extends Exception { | ||
|
||
constructor(private response: Response) { | ||
super("ProcessHttpClientResponseException", `Error making HttpClient request in queryable: [${response.status}] ${response.statusText}`); | ||
super.Log(); | ||
} | ||
export class ProcessHttpClientResponseException extends Error { | ||
|
||
protected getLogEntry(): Promise<LogEntry> { | ||
return this.response.json().then(json => <LogEntry>{ data: json, level: LogLevel.Error, message: this.message }); | ||
constructor(response: Response) { | ||
super(`Error making HttpClient request in queryable: [${response.status}] ${response.statusText}`); | ||
this.name = "ProcessHttpClientResponseException"; | ||
response.json().then(json => Logger.log({ data: json, level: LogLevel.Error, message: this.message })); | ||
} | ||
} | ||
|
||
export class NoCacheAvailableException extends Exception { | ||
export class NoCacheAvailableException extends Error { | ||
|
||
constructor(msg = "Cannot create a caching configuration provider since cache is not available.") { | ||
super("NoCacheAvailableException", msg); | ||
super.Log(); | ||
super(msg); | ||
this.name = "NoCacheAvailableException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class APIUrlException extends Exception { | ||
export class APIUrlException extends Error { | ||
|
||
constructor(msg = "Unable to determine API url.") { | ||
super("APIUrlException", msg); | ||
super.Log(); | ||
super(msg); | ||
this.name = "APIUrlException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class AuthUrlException extends Exception { | ||
export class AuthUrlException extends Error { | ||
|
||
constructor(protected data: any, msg = "Auth URL Endpoint could not be determined from data. Data logged.") { | ||
super("APIUrlException", msg); | ||
super.Log(); | ||
} | ||
|
||
protected getLogEntry(): Promise<LogEntry> { | ||
// if any loggers are listening give them the full details | ||
return Promise.resolve(<LogEntry>{ data: this.data, level: LogLevel.Error, message: this.message }); | ||
constructor(data: any, msg = "Auth URL Endpoint could not be determined from data. Data logged.") { | ||
super(msg); | ||
this.name = "APIUrlException"; | ||
Logger.log({ data: data, level: LogLevel.Error, message: this.message }); | ||
} | ||
} | ||
|
||
export class NodeFetchClientUnsupportedException extends Exception { | ||
export class NodeFetchClientUnsupportedException extends Error { | ||
|
||
constructor(msg = "Using NodeFetchClient in the browser is not supported.") { | ||
super("NodeFetchClientUnsupportedException", msg); | ||
this.Log(); | ||
super(msg); | ||
this.name = "NodeFetchClientUnsupportedException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class SPRequestExecutorUndefinedException extends Exception { | ||
export class SPRequestExecutorUndefinedException extends Error { | ||
|
||
constructor() { | ||
let msg = [ | ||
"SP.RequestExecutor is undefined. ", | ||
"Load the SP.RequestExecutor.js library (/_layouts/15/SP.RequestExecutor.js) before loading the PnP JS Core library.", | ||
].join(" "); | ||
super("SPRequestExecutorUndefinedException", msg); | ||
super.Log(); | ||
super(msg); | ||
this.name = "SPRequestExecutorUndefinedException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class MaxCommentLengthException extends Exception { | ||
export class MaxCommentLengthException extends Error { | ||
|
||
constructor(msg = "The maximum comment length is 1023 characters.") { | ||
super("MaxCommentLengthException", msg); | ||
this.Log(); | ||
super(msg); | ||
this.name = "MaxCommentLengthException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class NotSupportedInBatchException extends Exception { | ||
export class NotSupportedInBatchException extends Error { | ||
|
||
constructor(operation = "This operation") { | ||
super("NotSupportedInBatchException", `${operation} is not supported as part of a batch.`); | ||
super.Log(); | ||
super(`${operation} is not supported as part of a batch.`); | ||
this.name = "NotSupportedInBatchException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class ODataIdException extends Exception { | ||
|
||
constructor(protected data: any, msg = "Could not extract odata id in object, you may be using nometadata. Object data logged to logger.") { | ||
super("ODataIdException", msg); | ||
super.Log(); | ||
} | ||
export class ODataIdException extends Error { | ||
|
||
protected getLogEntry(): Promise<LogEntry> { | ||
// if any loggers are listening give them the full details | ||
return Promise.resolve(<LogEntry>{ data: this.data, level: LogLevel.Error, message: this.message }); | ||
constructor(data: any, msg = "Could not extract odata id in object, you may be using nometadata. Object data logged to logger.") { | ||
super(msg); | ||
this.name = "ODataIdException"; | ||
Logger.log({ data: data, level: LogLevel.Error, message: this.message }); | ||
} | ||
} | ||
|
||
export class BatchParseException extends Exception { | ||
export class BatchParseException extends Error { | ||
|
||
constructor(msg: string) { | ||
super("BatchParseException", msg); | ||
super.Log(); | ||
super(msg); | ||
this.name = "BatchParseException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class AlreadyInBatchException extends Exception { | ||
export class AlreadyInBatchException extends Error { | ||
|
||
constructor(msg = "This query is already part of a batch.") { | ||
super("AlreadyInBatchException", msg); | ||
super.Log(); | ||
super(msg); | ||
this.name = "AlreadyInBatchException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class FunctionExpectedException extends Exception { | ||
export class FunctionExpectedException extends Error { | ||
|
||
constructor(msg = "This query is already part of a batch.") { | ||
super("FunctionExpectedException", msg); | ||
super.Log(); | ||
super(msg); | ||
this.name = "FunctionExpectedException"; | ||
defaultLog(this); | ||
} | ||
} | ||
|
||
export class UrlException extends Exception { | ||
export class UrlException extends Error { | ||
|
||
constructor(msg: string) { | ||
super("UrlException", msg); | ||
super.Log(); | ||
super(msg); | ||
this.name = "UrlException"; | ||
defaultLog(this); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,5 +18,8 @@ | |
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"pretty": true | ||
} | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
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