Skip to content

Throw more helpful error if http output is incorrect #271

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

Merged
merged 3 commits into from
Dec 4, 2019
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
2 changes: 1 addition & 1 deletion src/WorkerChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class WorkerChannel implements IWorkerChannel {
if (version.startsWith("v8.")) {
let msg = "Incompatible Node.js version. The version you are using (" + version + ") is not supported with Azure Functions V3. Please use one of the following major versions: 10, 12.";
systemError(msg);
throw msg;
throw new InternalException(msg);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/converters/RpcHttpConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ function fromRpcHttpBody(body: rpc.ITypedData) {
* @param inputMessage An HTTP response object
*/
export function toRpcHttp(inputMessage): rpc.ITypedData {
// Check if we will fail to find any of these
if (typeof inputMessage !== 'object' || Array.isArray(inputMessage)) {
throw new Error("The HTTP response must be an 'object' type that can include properties such as 'body', 'status', and 'headers'. Learn more: https://go.microsoft.com/fwlink/?linkid=2112563");
}

let httpMessage: rpc.IRpcHttp = inputMessage;
httpMessage.headers = toRpcHttpHeaders(inputMessage.headers);
httpMessage.cookies = toRpcHttpCookieList(inputMessage.cookies || []);
Expand Down
18 changes: 16 additions & 2 deletions test/RpcHttpConverters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toRpcHttpCookieList } from '../src/converters';
import { toRpcHttpCookieList, toRpcHttp } from '../src/converters';
import { Cookie } from "../types/public/Interfaces";
import { expect } from 'chai';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('Rpc Converters', () => {
expect((<any>rpcCookies[2].expires).value.seconds).to.equal(819199440);
});

it('throws on invalid input', () => {
it('throws on invalid cookie input', () => {
expect(() => {
let cookieInputs = [
{
Expand Down Expand Up @@ -72,4 +72,18 @@ describe('Rpc Converters', () => {
toRpcHttpCookieList(<Cookie[]>cookieInputs);
}).to.throw("");
});

it('throws on array as http response', () => {
expect(() => {
let response = ["one", 2, "3"];
toRpcHttp(response);
}).to.throw("The HTTP response must be an 'object' type that can include properties such as 'body', 'status', and 'headers'. Learn more: https://go.microsoft.com/fwlink/?linkid=2112563");
});

it('throws on string as http response', () => {
expect(() => {
let response = "My output string";
toRpcHttp(response);
}).to.throw("The HTTP response must be an 'object' type that can include properties such as 'body', 'status', and 'headers'. Learn more: https://go.microsoft.com/fwlink/?linkid=2112563");
});
})