-
Notifications
You must be signed in to change notification settings - Fork 29
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
Showing
6 changed files
with
103 additions
and
59 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ yarn.lock | |
dist | ||
.vscode/ | ||
*.log | ||
.DS_Store |
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,55 @@ | ||
import { CombinedError } from 'urql' | ||
|
||
export enum OmnivoreErrorCode { | ||
GraphQLError = 'GRAPHQL_ERROR', | ||
NetworkError = 'NETWORK_ERROR', | ||
UnknownError = 'UNKNOWN_ERROR', | ||
} | ||
|
||
abstract class OmnivoreErrorBase<Code extends OmnivoreErrorCode> extends Error { | ||
abstract code: Code | ||
} | ||
|
||
class GraphQLError extends OmnivoreErrorBase<OmnivoreErrorCode> { | ||
code = OmnivoreErrorCode.GraphQLError | ||
constructor(public messages?: string[]) { | ||
super(messages?.join(', ')) | ||
} | ||
} | ||
|
||
class NetworkError extends OmnivoreErrorBase<OmnivoreErrorCode> { | ||
code = OmnivoreErrorCode.NetworkError | ||
constructor(public message: string) { | ||
super(message) | ||
} | ||
} | ||
|
||
class UnknownError extends OmnivoreErrorBase<OmnivoreErrorCode> { | ||
code = OmnivoreErrorCode.UnknownError | ||
constructor(public message: string) { | ||
super(message) | ||
} | ||
} | ||
|
||
export type OmnivoreError = GraphQLError | NetworkError | UnknownError | ||
|
||
export const buildOmnivoreError = ( | ||
data?: { __typename: string; errorCodes?: string[] }, | ||
error?: CombinedError, | ||
): OmnivoreError => { | ||
if (error) { | ||
if (error.graphQLErrors.length > 0) { | ||
return new GraphQLError(error.graphQLErrors.map((e) => e.message)) | ||
} | ||
|
||
if (error.networkError) { | ||
return new NetworkError(error.networkError.message) | ||
} | ||
} | ||
|
||
if (!data) { | ||
return new UnknownError('No data returned') | ||
} | ||
|
||
return new GraphQLError(data.errorCodes) | ||
} |
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,15 +1,18 @@ | ||
export { | ||
Omnivore, | ||
SearchParameters, | ||
SearchResponse, | ||
UpdatesSinceResponse, | ||
SaveByURLParameters, | ||
Node, | ||
PageInfo, | ||
PageType, | ||
SaveByURLResponse, | ||
ClientOptions, | ||
DeleteResponse, | ||
Highlight, | ||
HighlightType, | ||
Label, | ||
Node, | ||
Omnivore, | ||
PageInfo, | ||
PageType, | ||
SaveByURLParameters, | ||
SaveByURLResponse, | ||
SearchParameters, | ||
SearchResponse, | ||
UpdatesSinceResponse, | ||
} from './client' | ||
|
||
export { OmnivoreError, OmnivoreErrorCode } from './errors' |