Skip to content

Commit

Permalink
update error message so it doesn't look like an internal error from …
Browse files Browse the repository at this point in the history
…UI (#386)
  • Loading branch information
YingXue authored Jan 27, 2021
1 parent 523bf9e commit e32af38
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "azure-iot-explorer",
"version": "0.13.3",
"version": "0.13.4",
"description": "This project welcomes contributions and suggestions. Most contributions require you to agree to a\r Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\r the rights to use your contribution. For details, visit https://cla.microsoft.com.",
"main": "public/electron.js",
"build": {
Expand Down
31 changes: 2 additions & 29 deletions src/server/dataPlaneHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License
**********************************************************/
import express = require('express');
import { generateDataPlaneRequestBody, API_VERSION, processDataPlaneResponse } from './dataPlaneHelper'; // note: remove auto-generated dataPlaneHelper.js in order to run this test
import { generateDataPlaneRequestBody, processDataPlaneResponse } from './dataPlaneHelper'; // note: remove auto-generated dataPlaneHelper.js in order to run this test

describe('server', () => {
const hostName = 'testHub.private.azure-devices-int.net';
Expand Down Expand Up @@ -34,33 +34,6 @@ describe('server', () => {
);
});

it('generates data plane request without API version or query string specified in body', () => {
const req = {
body: {
body: '{"query":"\\n SELECT deviceId as DeviceId,\\n status as Status,\\n FROM devices WHERE STARTSWITH(devices.deviceId, \'test\')"}',
headers: { 'x-ms-max-item-count': 20 },
hostName,
httpMethod: 'POST',
path: 'devices/query',
sharedAccessSignature: `SharedAccessSignature sr=${hostName}%2Fdevices%2Fquery&sig=123&se=456&skn=iothubowner`
}
};
const requestBody = generateDataPlaneRequestBody(req as express.Request);
expect(requestBody).toEqual(
{
body: '{"query":"\\n SELECT deviceId as DeviceId,\\n status as Status,\\n FROM devices WHERE STARTSWITH(devices.deviceId, \'test\')"}',
headers: {
'Accept': 'application/json',
'Authorization': req.body.sharedAccessSignature,
'Content-Type': 'application/json',
'x-ms-max-item-count': 20
},
method: 'POST',
uri: `https://${hostName}/devices%2Fquery?api-version=${API_VERSION}`,
}
);
});

it('generates data plane response with success', () => {
// tslint:disable
const res: any = {
Expand Down Expand Up @@ -105,7 +78,7 @@ describe('server', () => {

it('generates data plane response with no httpResponse', () => {
const response = processDataPlaneResponse(null, null);
expect(response.body).toEqual({body: {Message: `Cannot read property 'headers' of null`}});
expect(response.body).toEqual({body: {Message: 'Failed to get any response from iot hub service.'}});
});

it('generates data plane response using device status code', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/server/dataPlaneHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const generateDataPlaneResponse = (httpRes: request.Response, body: any,
// tslint:disable-next-line:cyclomatic-complexity
export const processDataPlaneResponse = (httpRes: request.Response, body: any): {body: {body: any, headers?: any}, statusCode: number} => { // tslint:disable-line:no-any
try {
if(!httpRes) {
throw new Error('Failed to get any response from iot hub service.');
}
if (httpRes.headers && httpRes.headers[DEVICE_STATUS_HEADER]) { // handles happy failure cases when error code is returned as a header
let deviceResponseBody;
try {
Expand Down

0 comments on commit e32af38

Please sign in to comment.