-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from postmanlabs/release/v0.2.0
Release version v0.2.0
- Loading branch information
Showing
12 changed files
with
4,395 additions
and
576 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
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,15 @@ | ||
/** | ||
* constructor userError | ||
* @constructor | ||
* @param {*} message errorMessage | ||
* @param {*} data additional data to be reported | ||
*/ | ||
class UserError extends Error { | ||
constructor(message, data) { | ||
super(message); | ||
this.name = 'UserError'; | ||
this.data = data || {}; | ||
} | ||
} | ||
|
||
module.exports = UserError; |
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,46 @@ | ||
const _ = require('lodash'), | ||
wap = require('webapi-parser').WebApiParser, | ||
UserError = require('./UserError'); | ||
|
||
/** | ||
* Validates given RAML 1.0 definition using WebAPI Parser and | ||
* generates UserError or Unhandled error depending upon type of error. | ||
* | ||
* @param {Object} definition - RAML definition | ||
* @param {*} error - Original Error object | ||
* @param {Function} cb - Callback function | ||
* @returns {*} - Generated Error object | ||
*/ | ||
function generateError (definition, error, cb) { | ||
wap.raml10.parse(definition, '') | ||
.then((model) => { | ||
wap.raml10.validate(model) | ||
.then((report) => { | ||
if (report.conforms || report.results.length === 0) { | ||
if (error instanceof Error) { | ||
return cb(error); | ||
} | ||
|
||
const errorMessage = typeof error === 'string' ? error : | ||
_.get(error, 'message', 'Failed to generate collection.'); | ||
|
||
return cb(new Error(errorMessage)); | ||
} | ||
|
||
let lastReportRes = report.results.pop(), | ||
message = lastReportRes.message; | ||
|
||
return cb(new UserError(message, error)); | ||
}) | ||
.catch(() => { | ||
return cb(new UserError('Provided RAML 1.0 definition is invalid.', error)); | ||
}); | ||
}) | ||
.catch(() => { | ||
return cb(new UserError('Provided RAML 1.0 definition is invalid.', error)); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
generateError | ||
}; |
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
Oops, something went wrong.