Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error package to 10.4.0 #106

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions grafana/annotations/graphite.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ function Graphite(opts) {
var self = this;

if (!opts.name) {
throw errors.UnfulfilledRequirement({
component: 'grafana.annotations.Graphite',
unfulfilledArg: 'name'
});
throw errors.UnfulfilledRequirement(
"{component} missing requirement: {unfulfilledArg}",
{
component: 'grafana.annotations.Graphite',
unfulfilledArg: 'name'
}
);
}

if (!opts.target) {
throw errors.UnfulfilledRequirement({
component: 'grafana.annotations.Graphite',
unfulfilledArg: 'target'
});
throw errors.UnfulfilledRequirement(
"{component} missing requirement: {unfulfilledArg}",
{
component: 'grafana.annotations.Graphite',
unfulfilledArg: 'target'
}
);
}

var defaults = {
Expand Down
35 changes: 5 additions & 30 deletions grafana/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,12 @@
// THE SOFTWARE.

'use strict';
var TypedError = require('error/typed');
var SError = require('error').SError;

var UnfulfilledRequirement = TypedError({
type: 'grafana.errors.UnfulfilledRequirement',
message: '{component} missing requirement: {unfulfilledArg}',
component: null,
unfulfilledArg: null
});

var InvalidState = TypedError({
type: 'grafana.errors.InvalidState',
message: '{component} state is invalid: state.{invalidArg} {reason}',
component: null,
invalidArg: null,
reason: null
});

var Misconfigured = TypedError({
type: 'grafana.errors.Misconfigured',
message: 'Incorrect configuration: config.{invalidArg} {reason} - {resolution}',
invalidArg: null,
reason: null,
resolution: 'Must call grafana.configure before publishing'
});

var ResponseError = TypedError({
type: 'grafana.errors.RequestFailed',
message: 'request failed: {name}',
name: null,
response: null
});
class UnfulfilledRequirement extends SError {};
class InvalidState extends SError {};
class Misconfigured extends SError {};
class ResponseError extends SError {};
Comment on lines +24 to +27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we have an official node version we supported on this package? The class keyword was added on Node v4.3.2

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to setup engines in package.json

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #108


module.exports = {
UnfulfilledRequirement: UnfulfilledRequirement,
Expand Down
59 changes: 37 additions & 22 deletions grafana/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,48 @@ function publish(dashboard, opts) {
opts = opts || {};

if (!dashboard) {
throw errors.UnfulfilledRequirement({
component: "grafana.publish",
unfulfilledArg: "dashboard"
});
throw errors.UnfulfilledRequirement(
"{component} missing requirement: {unfulfilledArg}",
{
component: "grafana.publish",
unfulfilledArg: "dashboard"
}
);
}

const state = dashboard.state;
const cfg = config.getConfig();

if (!state || !state.title) {
throw errors.InvalidState({
component: "grafana.Dashboard",
invalidArg: "title",
reason: "undefined"
});
throw errors.InvalidState(
"{component} state is invalid: state.{invalidArg} {reason}",
{
component: "grafana.Dashboard",
invalidArg: "title",
reason: "undefined"
}
);
}

if (!cfg.url) {
throw errors.Misconfigured({
invalidArg: "url",
reason: "undefined",
resolution: "Must call grafana.configure before publishing"
});
throw errors.Misconfigured(
"Incorrect configuration: config.{invalidArg} {reason} - {resolution}",
{
invalidArg: "url",
reason: "undefined",
resolution: "Must call grafana.configure before publishing"
}
);
}

if (!cfg.cookie) {
throw errors.Misconfigured({
invalidArg: "cookie",
reason: "undefined"
});
throw errors.Misconfigured(
"Incorrect configuration: config.{invalidArg} {reason} - {resolution}",
{
invalidArg: "cookie",
reason: "undefined"
}
);
}

const headers = new fetch.Headers(cfg.headers || {});
Expand All @@ -80,10 +92,13 @@ function publish(dashboard, opts) {
console.log("Published the dashboard", state.title);
return resp.text();
} else {
throw errors.ResponseError({
name: resp.statusText,
response: resp
});
throw new errors.ResponseError(
"request failed: {name}",
{
name: resp.statusText,
response: resp
}
);
}
})
.catch(e => {
Expand Down
14 changes: 3 additions & 11 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"author": "Madan Thangavelu",
"license": "MIT",
"dependencies": {
"error": "^7.2.1",
"error": "^10.4.0",
"node-fetch": "^2.6.12",
"underscore": "^1.10.2",
"xtend": "^4.0.2"
Expand Down
8 changes: 4 additions & 4 deletions test/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ test("Publish dashboard - client error", function(assert) {
message: "Version mismatch"
});
publish(dashboard).catch(e => {
assert.equal(e.response.status, 412);
assert.equal(e.info().response.status, 412);
});
});

Expand All @@ -162,7 +162,7 @@ test("Publish dashboard - client error (invalid)", function(assert) {
.post("/dashboard")
.reply(400, { status: "error" });
publish(dashboard).catch(e => {
assert.equal(e.response.status, 400);
assert.equal(e.info().response.status, 400);
});
});

Expand All @@ -176,7 +176,7 @@ test("Publish dashboard - client error (n/a)", function t(assert) {
.post("/dashboard")
.reply(412, { status: "error" });
publish(dashboard).catch(e => {
assert.equal(e.response.status, 412);
assert.equal(e.info().response.status, 412);
});
});

Expand Down Expand Up @@ -215,7 +215,7 @@ test("Publish dashboard - server error", function(assert) {
.post("/dashboard")
.reply(500);
publish(dashboard).catch(e => {
assert.equal(e.response.status, 500);
assert.equal(e.info().response.status, 500);
});
});

Expand Down
Loading