Skip to content

Commit e01bd61

Browse files
committed
gh-88: Adjusting error messages
1 parent 1a1f0bc commit e01bd61

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/connection/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ export default class Connection {
4343
params.host = params.host.slice(0, -1);
4444
}
4545

46-
const protocolPattern = /^(https?:\/\/|ftp:\/\/|file:\/\/)/;
46+
const protocolPattern = /^(https?|ftp|file)(?::\/\/)/;
4747
const extractedSchemeMatch = params.host.match(protocolPattern);
4848

4949
// Check for the existence of scheme in params
5050
if (params.scheme) {
5151
// If the host contains a scheme different than provided scheme, replace it and throw a warning
52-
if (extractedSchemeMatch && extractedSchemeMatch[0] !== `${params.scheme}://`) {
52+
if (extractedSchemeMatch && extractedSchemeMatch[1] !== `${params.scheme}`) {
5353
throw new Error(
54-
`The host contains a different protocol than specified in the scheme (scheme: ${params.scheme}:// != host: ${extractedSchemeMatch[0]})`
54+
`The host contains a different protocol than specified in the scheme (scheme: ${params.scheme} != host: ${extractedSchemeMatch[1]})`
5555
);
5656
} else if (!extractedSchemeMatch) {
5757
// If no scheme in the host, simply prefix with the provided scheme
@@ -60,7 +60,7 @@ export default class Connection {
6060
// If there's no scheme in params, ensure the host starts with a recognized protocol
6161
} else if (!extractedSchemeMatch) {
6262
throw new Error(
63-
'The host must start with a recognized protocol (e.g., http:// or https://) if no scheme is provided.'
63+
'The host must start with a recognized protocol (e.g., http or https) if no scheme is provided.'
6464
);
6565
}
6666

src/connection/unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('mock server auth tests', () => {
174174
};
175175

176176
expect(createConnection).toThrow(
177-
'The host contains a different protocol than specified in the scheme (scheme: https:// != host: http://)'
177+
'The host contains a different protocol than specified in the scheme (scheme: https != host: http)'
178178
);
179179
});
180180

@@ -189,7 +189,7 @@ describe('mock server auth tests', () => {
189189
};
190190

191191
expect(createConnection).toThrow(
192-
'The host must start with a recognized protocol (e.g., http:// or https://) if no scheme is provided.'
192+
'The host must start with a recognized protocol (e.g., http or https) if no scheme is provided.'
193193
);
194194
});
195195

0 commit comments

Comments
 (0)