Skip to content

Commit

Permalink
Merge pull request #4 from digio/fix/improve-error-messages-further
Browse files Browse the repository at this point in the history
fix: improve error message
  • Loading branch information
uglow authored Dec 3, 2020
2 parents d8d179b + bbe9e23 commit abf8c37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('CLI', () => {
expect(result).toMatchInlineSnapshot(`
"warn: Ignore (no x-examples parameters) - GET /posts/{id} 200
warn: Ignore (no x-examples parameters) - GET /posts/{id} 404
[31merror[39m: An x-examples parameter for \\"userId\\" is missing from /posts.responses.200.x-examples.default.parameters[1]
[31merror[39m: An x-examples parameter for \\"userId\\" is missing from /posts.get.responses.200.x-examples.default.parameters[1]
"
`);
});
Expand Down
13 changes: 9 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const EXAMPLE_PROP_NAME = 'x-examples';
const IGNORE_PROPERTY_PROP_NAME = 'x-test-ignore-paths';
const IGNORE_ENDPOINT_NAME = 'x-ignore';
const MOCK_FILE_PROP = 'x-mock-file';
const MISSING_PARAM_ERROR_MESSAGE = 'Missing parameter object!';

// Returns fetch config for calling all the endpoints
function getFetchConfigForAPIEndpoints(params) {
Expand Down Expand Up @@ -253,9 +254,13 @@ async function resolveFetchConfigParams(params) {
fconfig.resolvedParams = fconfig.resolvedParams || [];
fconfig.resolvedParams[index] = paramValue;
} catch (err) {
throw new Error(
`An ${EXAMPLE_PROP_NAME} parameter for "${paramName}" is missing from ${fconfig.path}.responses.${fconfig.expectedStatusCode}.${EXAMPLE_PROP_NAME}.${fconfig.exampleName}.parameters[${index}]`,
);
if (err.message === MISSING_PARAM_ERROR_MESSAGE) {
throw new Error(
`An ${EXAMPLE_PROP_NAME} parameter for "${paramName}" is missing from ${fconfig.path}.${fconfig.config.method}.responses.${fconfig.expectedStatusCode}.${EXAMPLE_PROP_NAME}.${fconfig.exampleName}.parameters[${index}]`,
);
}
// re-throw the error otherwise.
throw err;
}
}),
);
Expand All @@ -276,7 +281,7 @@ async function resolveFetchConfigParams(params) {

function getParamValue(serverUrl, inputObj, absSpecFilePath) {
if (!inputObj) {
throw new Error(`Missing parameter object!`);
throw new Error(MISSING_PARAM_ERROR_MESSAGE);
}
if (inputObj.script !== undefined) {
// TODO: The script MUST be relative to the spec file!
Expand Down

0 comments on commit abf8c37

Please sign in to comment.