-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better validation error messages for headers
- Loading branch information
Adam Kliment
committed
May 21, 2015
1 parent
457dd69
commit 4420ef6
Showing
5 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = (message) -> | ||
if message.indexOf("Missing required property:") > 1 | ||
headerName = message.split("Missing required property: ")[1] | ||
newMessage = "Header '#{headerName}' is missing" | ||
|
||
else if message.indexOf("No enum match for: ") > 1 | ||
splitted = message.split '\' No enum match for: "' | ||
|
||
headerName = splitted[0] | ||
headerName = headerName.replace(/^At '\//, '') | ||
|
||
headerValue = splitted[1] | ||
headerValue = headerValue.replace(/"$/, '') | ||
|
||
|
||
newMessage = "Header '#{headerName}' doesn't have value '#{headerValue}'" | ||
|
||
else | ||
throw new Error 'Unknown tv4 error message can\'t convert to headers message.' | ||
|
||
return newMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{assert} = require 'chai' | ||
tv4ToHeadersMessage = require '../../../src/utils/tv4-to-headers-message' | ||
|
||
describe 'tv4ToHeadersMessages()', -> | ||
|
||
describe 'when message for missing header', -> | ||
it 'should return message with right text', -> | ||
tv4Message = 'At \'/header2\' Missing required property: header2' | ||
message = tv4ToHeadersMessage(tv4Message) | ||
assert.equal message, "Header 'header2' is missing" | ||
|
||
describe 'when message for different value', -> | ||
it 'should return message with right text', -> | ||
tv4Message = 'At \'/content-type\' No enum match for: "application/fancy-madiatype"' | ||
message = tv4ToHeadersMessage(tv4Message) | ||
assert.equal message, "Header 'content-type' doesn't have value 'application/fancy-madiatype'" | ||
|
||
describe 'when unknonw message', -> | ||
it 'should throw an error', -> | ||
fn = () -> | ||
tv4ToHeadersMessage("String does not match pattern: {pattern}") | ||
assert.throws fn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters