-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resource documentation for SDK reference (#476)
This PR has documentation adds for all the resources. Also changes the following: - Refactor Auth to reflect the recent changes to the endpoints - Refactor Errors to support API + OAuth errors as well as timeout errors - Move availability into the calendar resource
- Loading branch information
1 parent
d1c21e1
commit 2ea65dd
Showing
18 changed files
with
472 additions
and
368 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
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,50 +1,93 @@ | ||
import { | ||
NylasApiErrorResponse, | ||
AuthErrorResponse, | ||
TokenValidationErrorResponse, | ||
} from './response'; | ||
import { NylasApiErrorResponse, AuthErrorResponse } from './response'; | ||
|
||
/** | ||
* Extended Error class for errors returned from the Nylas API | ||
* | ||
* Properties: | ||
* Base class for all Nylas API errors. | ||
*/ | ||
export class NylasApiError extends Error { | ||
export abstract class AbstractNylasApiError extends Error { | ||
/** | ||
* The unique identifier of the request. | ||
*/ | ||
requestId?: string; | ||
/** | ||
* The HTTP status code of the error response. | ||
*/ | ||
statusCode?: number; | ||
} | ||
|
||
/** | ||
* Base class for all Nylas SDK errors. | ||
*/ | ||
export abstract class AbstractNylasSdkError extends Error {} | ||
|
||
/** | ||
* Class representation of a general Nylas API error. | ||
*/ | ||
export class NylasApiError extends AbstractNylasApiError { | ||
/** | ||
* Error type. | ||
*/ | ||
type: string; | ||
requestId: string; | ||
/** | ||
* Provider Error. | ||
*/ | ||
providerError: any; | ||
|
||
constructor(apiError: NylasApiErrorResponse) { | ||
constructor(apiError: NylasApiErrorResponse, statusCode?: number) { | ||
super(apiError.error.message); | ||
this.type = apiError.error.type; | ||
this.requestId = apiError.requestId; | ||
this.providerError = apiError.error.providerError; | ||
this.statusCode = statusCode; | ||
} | ||
} | ||
|
||
export class NylasAuthError extends Error { | ||
type: string; | ||
requestId: string; | ||
providerError: any; | ||
/** | ||
* Class representing an OAuth error returned by the Nylas API. | ||
*/ | ||
export class NylasOAuthError extends AbstractNylasApiError { | ||
/** | ||
* Error type. | ||
*/ | ||
error: string; | ||
/** | ||
* Error code used for referencing the docs, logs, and data stream. | ||
*/ | ||
errorCode: number; | ||
/** | ||
* Human readable error description. | ||
*/ | ||
errorDescription: string; | ||
/** | ||
* URL to the related documentation and troubleshooting regarding this error. | ||
*/ | ||
errorUri: string; | ||
|
||
constructor(apiError: AuthErrorResponse) { | ||
constructor(apiError: AuthErrorResponse, statusCode?: number) { | ||
super(apiError.errorDescription); | ||
this.type = apiError.error; | ||
this.requestId = apiError.requestId; | ||
this.providerError = apiError.errorDescription; | ||
this.error = apiError.error; | ||
this.errorCode = apiError.errorCode; | ||
this.errorDescription = apiError.errorDescription; | ||
this.errorUri = apiError.errorUri; | ||
this.statusCode = statusCode; | ||
} | ||
} | ||
export class NylasTokenValidationError extends Error { | ||
type: string; | ||
requestId: string; | ||
providerError: any; | ||
|
||
constructor(apiError: TokenValidationErrorResponse) { | ||
super(apiError.error.message); | ||
this.type = apiError.error.type; | ||
this.requestId = apiError.error.requestId; | ||
this.providerError = apiError.error.message; | ||
/** | ||
* Error thrown when the Nylas SDK times out before receiving a response from the server | ||
*/ | ||
export class NylasSdkTimeoutError extends AbstractNylasSdkError { | ||
/** | ||
* The URL that timed out | ||
*/ | ||
url: string; | ||
/** | ||
* The timeout value set in the Nylas SDK, in seconds | ||
*/ | ||
timeout: number; | ||
|
||
constructor(url: string, timeout: number) { | ||
super('Nylas SDK timed out before receiving a response from the server.'); | ||
this.url = url; | ||
this.timeout = timeout; | ||
} | ||
} | ||
|
||
// TODO: sdk error models? |
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
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
Oops, something went wrong.