Skip to content

Commit

Permalink
Update package.json version to 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
petrpavlik committed Oct 23, 2024
1 parent a5629da commit 408943b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run NPM Test",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "test"],
"skipFiles": ["<node_internals>/**"]
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indiepitcher",
"version": "1.0.1",
"version": "1.1.0",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class IndiePitcherResponseError extends Error {
statusCode: number;

constructor(message: string, statusCode: number) {
super(message);
this.name = 'IndiePitcherError';
this.statusCode = statusCode;
}
}
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
SendEmailToContact,
SendEmailToMailingList,
} from './dtos';
import { IndiePitcherResponseError } from './errors';
import type {
DataResponse,
EmptyResponse,
Expand All @@ -32,8 +33,8 @@ export class IndiePitcher {
const response = await fetch(`${this.baseUrl}${path}`, options);

if (!response.ok) {
const error = await response.json();
throw new Error(error);
const json = await response.json();
throw new IndiePitcherResponseError(json.reason ?? 'Unknown reason', response.status);
}

const data = await response.json();
Expand Down
10 changes: 10 additions & 0 deletions src/indiepitcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IndiePitcher } from '.';
import type { IndiePitcherResponseError } from './errors';

require('dotenv').config();
const apiKey = process.env.API_KEY;
Expand All @@ -10,6 +11,15 @@ afterEach(() => {
return new Promise((resolve) => setTimeout(resolve, 1000));
});

test('invalid API key', async () => {
const indiePitcher = new IndiePitcher('xxx');
try {
await indiePitcher.listMailingLists();
} catch (error) {
expect((error as IndiePitcherResponseError).message).toBe('Unauthorized');
}
});

test('list mailing lists', async () => {
const data = await indiePitcher.listMailingLists();
expect(data.data.length).toBe(2);
Expand Down

0 comments on commit 408943b

Please sign in to comment.