-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reverts back to errors but with detail
- Loading branch information
1 parent
a5a16e9
commit e7c8f49
Showing
5 changed files
with
28 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { TumblrAPIResponse } from "../interfaces"; | ||
|
||
export class TumblrAPIError extends Error { | ||
public response: TumblrAPIResponse; | ||
public queryURL: string; | ||
|
||
constructor(message: TumblrAPIResponse, queryURL: string) { | ||
super(`${message.meta.status}: ${message.meta.msg}`); | ||
this.name = "TumblrAPIError"; | ||
this.response = message; | ||
this.queryURL = queryURL; | ||
} | ||
} |
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 * from "./TumblrAPIError"; |
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,2 +1,3 @@ | ||
export * from "./classes"; | ||
export * from "./functions"; | ||
export * from "./interfaces"; |
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,10 +1,15 @@ | ||
import { accessTumblrAPI } from "../src"; | ||
import { accessTumblrAPI, TumblrAPIError } from "../src"; | ||
|
||
const token = process.env.TUMBLR_TOKEN; | ||
|
||
if (!token) throw new Error("No token provided"); | ||
|
||
it("should error on invalid path", async () => { | ||
const response = await accessTumblrAPI(token, "invalid/path"); | ||
expect(response.meta.status).toBe(404); | ||
const error = await accessTumblrAPI(token, "invalid/path").catch<Error>(e => e); | ||
expect(error instanceof TumblrAPIError).toBe(true); | ||
if (error instanceof TumblrAPIError) { | ||
expect(error.response.meta.status).toBe(404); | ||
expect(error.response.meta.msg).toBe("Not Found"); | ||
expect(error.queryURL).toBe("https://api.tumblr.com/v2/invalid/path?"); | ||
} | ||
}); |