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

TTN MQTT & device management (#8) #13

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use standard HTTP codes
  • Loading branch information
noerw committed Jan 11, 2018
commit 1605e5bafc175a5a4be0f635948de823bd0e2354
6 changes: 3 additions & 3 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ class BoxNotFoundError extends TTNError {
}

/**
* Thrown with { code: 422 } when the received payload was malformed.
* Thrown with { code: 400 } when the received payload was malformed.
* @param {string} message
*/
class PayloadError extends TTNError {
constructor (message) {
super(`Invalid payload: ${message}`);
this.code = 422;
this.code = 400;
}
}

/**
* Thrown with { code: 422 } when the received payload content could not be parsed.
* Thrown with { code: 400 } when the received payload content could not be parsed.
* @param {string} message
* @param {string} decoder The name of the decoder that is erroring
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/v1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const sendResponse = function sendResponse (req, res, next) {
(r instanceof Error && !(r instanceof TTNError)) || // filter non TTNError.code values
!code
) {
code = 501;
code = 500;
}

res.status(code).json({ code, message });
Expand Down
14 changes: 7 additions & 7 deletions test/02v1_1_httpintegration-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe('POST /v1.1 -- TTN HTTP Integration webhook', () => {
});
});

it('should respond 422 for empty request payloads', () => {
it('should respond 400 for empty request payloads', () => {
return chakram.post(URL, {}).then(res => {
expect(res).to.have.status(422);
expect(res).to.have.status(400);

return chakram.wait();
});
Expand Down Expand Up @@ -135,11 +135,11 @@ describe('POST /v1.1 -- TTN HTTP Integration webhook', () => {
});
});

it('should respond 422 for invalid request payload_raw', () => {
it('should respond 400 for invalid request payload_raw', () => {
TTNpayload_sbhome_valid.payload_raw = 'asdf';

return chakram.post(URL, TTNpayload_sbhome_valid).then(res => {
expect(res).to.have.status(422);
expect(res).to.have.status(400);

return chakram.wait();
});
Expand Down Expand Up @@ -167,18 +167,18 @@ describe('POST /v1.1 -- TTN HTTP Integration webhook', () => {
TTNpayload_json_valid.dev_id = 'my-dev-id'; // change to box with sensebox/home profile

return chakram.post(URL, TTNpayload_json_valid).then(res => {
expect(res).to.have.status(422);
expect(res).to.have.status(400);
TTNpayload_json_valid.dev_id = 'jsonttnbox';

return chakram.wait();
});
});

it('should respond 422 for invalid request payload_fields', () => {
it('should respond 400 for invalid request payload_fields', () => {
delete TTNpayload_json_valid.payload_fields;

return chakram.post(URL, TTNpayload_json_valid).then(res => {
expect(res).to.have.status(422);
expect(res).to.have.status(400);

return chakram.wait();
});
Expand Down