-
Notifications
You must be signed in to change notification settings - Fork 14
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 #506 from uploadcare/fix/add-missing-server-errors…
…-types Refactor errors
- Loading branch information
Showing
48 changed files
with
335 additions
and
195 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,20 +1,25 @@ | ||
import { CancelError } from './CancelError' | ||
import { UploadcareError } from './UploadcareError' | ||
|
||
describe('CancelError', () => { | ||
it('should have "isCancel" property with "true" value', async () => { | ||
it('should have "isCancel" property with "true" value', () => { | ||
const cancelError = new CancelError('Cancelled!') | ||
expect(cancelError.isCancel).toBe(true) | ||
}) | ||
|
||
it('should have default messgage', async () => { | ||
it('should have default messgage', () => { | ||
const cancelError = new CancelError() | ||
expect(cancelError.message).toBe('Request canceled') | ||
expect(cancelError.isCancel).toBe(true) | ||
}) | ||
|
||
it('should be able to pass message', async () => { | ||
it('should be able to pass message', () => { | ||
const cancelError = new CancelError('Message') | ||
expect(cancelError.message).toBe('Message') | ||
expect(cancelError.isCancel).toBe(true) | ||
}) | ||
|
||
it('should be instanceof UploadcareError', () => { | ||
expect(new CancelError()).toBeInstanceOf(UploadcareError) | ||
}) | ||
}) |
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,7 +1,12 @@ | ||
export class CancelError extends Error { | ||
import { UploadcareError } from './UploadcareError' | ||
|
||
export class CancelError extends UploadcareError { | ||
isCancel = true | ||
|
||
constructor(message = 'Request canceled') { | ||
super(message) | ||
|
||
this.name = 'CancelError' | ||
Object.setPrototypeOf(this, CancelError.prototype) | ||
} | ||
} |
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,19 @@ | ||
import { NetworkError } from './NetworkError' | ||
import { UploadcareError } from './UploadcareError' | ||
|
||
describe('NetworkError', () => { | ||
it('should work', () => { | ||
const progressEvent = new Event('ProgressEvent') as ProgressEvent | ||
const error = new NetworkError(progressEvent) | ||
expect(error.name).toBe('NetworkError') | ||
expect(error.message).toBe('Network error') | ||
expect(error instanceof NetworkError).toBeTruthy() | ||
expect(error.originalProgressEvent).toBe(progressEvent) | ||
}) | ||
|
||
it('should be instanceof UploadcareError', () => { | ||
const progressEvent = new Event('ProgressEvent') as ProgressEvent | ||
const error = new NetworkError(progressEvent) | ||
expect(error).toBeInstanceOf(UploadcareError) | ||
}) | ||
}) |
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,15 @@ | ||
import { UploadcareError } from './UploadcareError' | ||
|
||
export class NetworkError extends UploadcareError { | ||
originalProgressEvent: ProgressEvent | ||
|
||
constructor(progressEvent: ProgressEvent) { | ||
super() | ||
|
||
this.name = 'NetworkError' | ||
this.message = 'Network error' | ||
Object.setPrototypeOf(this, NetworkError.prototype) | ||
|
||
this.originalProgressEvent = progressEvent | ||
} | ||
} |
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,8 @@ | ||
import { UploadcareError } from './UploadcareError' | ||
|
||
describe('UploadcareError', () => { | ||
it('should be instanceof Error', async () => { | ||
const uploadcareError = new UploadcareError('This is error!') | ||
expect(uploadcareError instanceof Error).toBe(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 @@ | ||
export class UploadcareError extends Error {} |
12 changes: 0 additions & 12 deletions
12
packages/api-client-utils/src/UploadcareNetworkError.test.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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.