Skip to content

Commit

Permalink
Adds the createError module for use in Telescope (#5)
Browse files Browse the repository at this point in the history
* Fixed CreateError module, use http-errors

* removed merge conflict errors

* Added Docs in README

Co-authored-by: David Humphrey <david.andrew.humphrey@gmail.com>
  • Loading branch information
Metropass and humphd authored Mar 17, 2021
1 parent 9686739 commit 19d58db
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 177 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ In its most basic form, a Satellite-based microservice looks like this:
const {
Satellite, // the Satellite constructor
logger, // pre-configured logger
} = require("@senecacdot/satellite");
} = require('@senecacdot/satellite');

// Define your microservice
const service = new Satellite();

// Add your routes to the service's router
service.router.get("/my-route", (req, res) => {
res.json({ message: "hello world" });
service.router.get('/my-route', (req, res) => {
res.json({ message: 'hello world' });
});

// Start the service on the specified port
service.start(8888, () => {
logger.info("Satellite Microservice running on port 8888");
logger.info('Satellite Microservice running on port 8888');
});
```

Expand Down Expand Up @@ -158,17 +158,31 @@ router.get('/admin', isAuthenticated(), isAuthorized({ roles: ["admin"] }), (req
The `logger` object is a pre-configured logger based on [Pino](https://getpino.io/#/).
```js
const { logger } = require("@senecacdot/satellite");
const { logger } = require('@senecacdot/satellite');
logger.info("Hello World!");
logger.info('Hello World!');
```
### Hash
The `hash()` function is a convenience hashing function, which returns a 10 character hash:
```js
const { hash } = require("@senecacdot/satellite");
const { hash } = require('@senecacdot/satellite');
const id = hash("http://someurl.com");
const id = hash('http://someurl.com');
```
### Create Error
The `createError()` function creates a unique HTTP Error Object which is based on [http-errors](https://www.npmjs.com/package/http-errors).
```js
const { createError } = require('@senecacdot/satellite');
const e = createError(404, 'This is a message that describes your Error object');
console.log(e.status); // of type: Number
console.log(e.message); // of type: String
```
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { createRouter } = require("./app");
module.exports.Satellite = require("./satellite");
module.exports.logger = require("./logger");
module.exports.hash = require("./hash");
module.exports.createError = require("http-errors");
module.exports.Router = (options) => createRouter(options);
module.exports.isAuthenticated = isAuthenticated;
module.exports.isAuthorized = isAuthorized;
Loading

0 comments on commit 19d58db

Please sign in to comment.