Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle redirect chunk fetch error
- Loading branch information
Showing
9 changed files
with
89 additions
and
11 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
43 changes: 43 additions & 0 deletions
43
...__/infra/usecases/to-notion-api-content-responses/validation/page-chunk-validator.test.ts
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,43 @@ | ||
import { PageChunkValidator } from '../../../../../src/infra/usecases/to-notion-api-content-responses/validation/page-chunk'; | ||
|
||
describe('PageChunkValidator', () => { | ||
it('should not return an error if status is 200', () => { | ||
const sut = new PageChunkValidator('any_id', 200); | ||
|
||
const error = sut.validate(); | ||
|
||
expect(error).toBeNull(); | ||
}); | ||
|
||
it('should return NotionPageAccessError error if status is 401', () => { | ||
const sut = new PageChunkValidator('any_id', 401); | ||
|
||
const error = sut.validate(); | ||
|
||
expect(error?.name).toBe('NotionPageAccessError'); | ||
}); | ||
|
||
it('should return NotionPageAccessError error if status is 403', () => { | ||
const sut = new PageChunkValidator('any_id', 403); | ||
|
||
const error = sut.validate(); | ||
|
||
expect(error?.name).toBe('NotionPageAccessError'); | ||
}); | ||
|
||
it('should return NotionPageNotFound error if status is 404', () => { | ||
const sut = new PageChunkValidator('any_id', 404); | ||
|
||
const error = sut.validate(); | ||
|
||
expect(error?.name).toBe('NotionPageNotFound'); | ||
}); | ||
|
||
it('should return NotionPageNotFound error if status is 400', () => { | ||
const sut = new PageChunkValidator('any_id', 400); | ||
|
||
const error = sut.validate(); | ||
|
||
expect(error?.name).toBe('NotionPageNotFound'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class NotionPageNotFound extends Error { | ||
constructor(pageId: string) { | ||
super( | ||
`Can not find Notion Page of id ${pageId}. Is the url correct? It is the original page or a redirect page (not supported)?`, | ||
); | ||
this.name = 'NotionPageNotFound'; | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/infra/usecases/to-notion-api-content-responses/validation/page-chunk.ts
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,24 @@ | ||
import { NotionPageAccessError, NotionPageNotFound } from '../../../../infra/errors'; | ||
import { Validation } from '../../../protocols/validation'; | ||
|
||
export class PageChunkValidator implements Validation { | ||
private readonly _notionPageId: string; | ||
private readonly _pageChunkStatus: number; | ||
|
||
constructor(notionPageId: string, pageChunkStatus: number) { | ||
this._notionPageId = notionPageId; | ||
this._pageChunkStatus = pageChunkStatus; | ||
} | ||
|
||
validate(): Error | null { | ||
if ([401, 403].includes(this._pageChunkStatus)) { | ||
return new NotionPageAccessError(this._notionPageId); | ||
} | ||
|
||
if ([400, 404].includes(this._pageChunkStatus)) { | ||
return new NotionPageNotFound(this._notionPageId); | ||
} | ||
|
||
return null; | ||
} | ||
} |