Skip to content

Commit

Permalink
Release. Bump version number
Browse files Browse the repository at this point in the history
  • Loading branch information
bryaningl3 committed Jun 28, 2023
1 parent 951f982 commit 75faa2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@barchart/common-js",
"version": "4.28.1",
"version": "4.29.0",
"description": "Library of common JavaScript utilities",
"author": {
"name": "Bryan Ingle",
Expand Down
32 changes: 20 additions & 12 deletions test/SpecRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ module.exports = (() => {
'use strict';

/**
* Describes all of the reasons for API failure. Since there can be multiple reasons, the reasons are
* stored in a tree structure.
* Describes all of the reasons for API failure. Since there can be multiple
* reasons, the reasons are stored in a tree structure.
*
* @public
* @param {Object=} data - Data regarding the API request itself, likely independent of the failure data (which is maintained in the tree structure).
*/
class FailureReason {
constructor(data) {
this._data = data || null;
this._head = new Tree();
this._current = this._head;
this._root = new Tree();
this._current = this._root;
}

/**
Expand All @@ -45,10 +45,18 @@ module.exports = (() => {
* Resets the current node to the head of the tree.
*
* @public
* @param {Boolean=} previous
* @returns {FailureReason} - The current instance, allowing for method chaining.
*/
reset() {
this._current = this._head;
reset(previous) {
assert.argumentIsOptional(previous, 'previous', Boolean);
let node;
if (previous && this._current.getIsInner()) {
node = this._current.getParent();
} else {
node = this._root;
}
this._current = node;
return this;
}

Expand All @@ -59,15 +67,15 @@ module.exports = (() => {
* @returns {Array}
*/
format() {
const reasons = this._head.toJSObj(item => {
const reasons = this._root.toJSObj(item => {
const formatted = {};
formatted.code = item ? item.type.code : null;
formatted.message = item ? item.format(this._data) : null;
if (item && item.type.verbose) {
formatted.data = item.data;
}
return formatted;
});
}, true);
return reasons.children;
}

Expand All @@ -81,7 +89,7 @@ module.exports = (() => {
*/
hasFailureType(type) {
assert.argumentIsRequired(type, 'type', FailureType, 'FailureType');
return this._head.search(item => item.type === type, false, false) !== null;
return this._root.search(item => item.type === type, false, false) !== null;
}

/**
Expand All @@ -92,7 +100,7 @@ module.exports = (() => {
* @returns {Boolean}
*/
getIsSevere() {
return this._head.search(item => item.type.severe, false, false) !== null;
return this._root.search(item => item.type.severe, false, false) !== null;
}

/**
Expand All @@ -103,7 +111,7 @@ module.exports = (() => {
* @returns {Number|null}
*/
getErrorCode() {
const node = this._head.search(item => item.type.error !== null, true, false);
const node = this._root.search(item => item.type.error !== null, true, false);
if (node !== null) {
return node.getValue().type.error;
} else {
Expand Down Expand Up @@ -150,7 +158,7 @@ module.exports = (() => {
static getHttpStatusCode(reason) {
assert.argumentIsRequired(reason, 'reason', FailureReason, 'FailureReason');
let returnVal = null;
reason._head.walk(item => {
reason._root.walk(item => {
let code = FailureType.getHttpStatusCode(item.type);
if (returnVal === null || returnVal !== 400) {
returnVal = code;
Expand Down

0 comments on commit 75faa2c

Please sign in to comment.