Skip to content

Commit

Permalink
Fixed the previous packaging: RequestEvent class released by error
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Dec 8, 2017
1 parent 2678e99 commit 4f5d605
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
34 changes: 4 additions & 30 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ exports.Client = class Client extends EventEmitter {
* @param {URL} endPoint The URL of the end point to query.
* @param {object} fields The fields describing the query body.
* @return {Promise<string>} The response as string.
* @emits {RequestEvent} The "request" event.
* @emits {RequestEvent} The "response" event.
* @emits {Request} The "request" event.
* @emits {Reponse} The "response" event.
*/
async _fetch(endPoint, fields) {
let body = new URLSearchParams(Object.assign(this.blog.toJSON(), fields));
Expand All @@ -135,38 +135,12 @@ exports.Client = class Client extends EventEmitter {
body
});

this.emit('request', new exports.RequestEvent(req));
this.emit('request', req);
let res = await fetch(req);
this.emit('response', new exports.RequestEvent(req, res));
this.emit('response', req, res);

if (!res.ok) throw new Error('An error occurred while querying the end point.');
if (res.headers.has(Client.debugHeader)) throw new Error(res.headers.get(Client.debugHeader));
return res.text();
}
};

/**
* The event parameter used for request events.
*/
exports.RequestEvent = class RequestEvent {

/**
* Initializes a new instance of the class.
* @param {Request} request The client request.
* @param {Response} [response] The server response.
*/
constructor(request, response = null) {

/**
* The client request.
* @type {Request}
*/
this.request = request;

/**
* The server response.
* @type {Response}
*/
this.response = response;
}
};
5 changes: 2 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

const {Author} = require('./author');
const {Blog} = require('./blog');
const {Client, RequestEvent} = require('./client');
const {Client} = require('./client');
const {Comment, CommentType} = require('./comment');

module.exports = {
Author,
Blog,
Client,
Comment,
CommentType,
RequestEvent
CommentType
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "./lib/index.js",
"name": "@cedx/akismet",
"repository": "cedx/akismet.js",
"version": "13.0.0",
"version": "13.0.1",
"dependencies": {
"node-fetch": "^1.7.3"
},
Expand Down

0 comments on commit 4f5d605

Please sign in to comment.