Skip to content

Commit aa3ca41

Browse files
[FSSDK-12865] error message improv. + test addition
1 parent c458c5a commit aa3ca41

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

lib/message/error_message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const OUT_OF_BOUNDS =
8787
export const REQUEST_TIMEOUT = 'Request timeout';
8888
export const REQUEST_ERROR = 'Request error';
8989
export const NO_STATUS_CODE_IN_RESPONSE = 'No status code in response';
90+
export const INVALID_REQUEST_URL = 'Invalid request URL: %s';
9091
export const UNSUPPORTED_PROTOCOL = 'Unsupported protocol: %s';
9192
export const RETRY_CANCELLED = 'Retry cancelled';
9293
export const ONLY_POST_REQUESTS_ARE_SUPPORTED = 'Only POST requests are supported';

lib/utils/http_request_handler/request_handler.node.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ describe('NodeRequestHandler', () => {
173173
await expect(request.responsePromise).rejects.toThrow();
174174
});
175175

176+
it('should return a rejected response promise when the URL is malformed', async () => {
177+
const request = nodeRequestHandler.makeRequest('not a valid url', {}, 'get');
178+
179+
await expect(request.responsePromise).rejects.toThrow();
180+
});
181+
176182
it('should return a rejected promise when there is a request error', async () => {
177183
const scope = nock(host)
178184
.get(path)

lib/utils/http_request_handler/request_handler.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { AbortableRequest, Headers, RequestHandler, Response } from './http';
1919
import decompressResponse from 'decompress-response';
2020
import { LoggerFacade } from '../../logging/logger';
2121
import { REQUEST_TIMEOUT_MS } from '../enums';
22-
import { NO_STATUS_CODE_IN_RESPONSE, REQUEST_ERROR, REQUEST_TIMEOUT, UNSUPPORTED_PROTOCOL } from 'error_message';
22+
import { INVALID_REQUEST_URL, NO_STATUS_CODE_IN_RESPONSE, REQUEST_ERROR, REQUEST_TIMEOUT, UNSUPPORTED_PROTOCOL } from 'error_message';
2323
import { OptimizelyError } from '../../error/optimizly_error';
2424
import { Platform } from '../../platform_support';
2525
/**
@@ -50,7 +50,7 @@ export class NodeRequestHandler implements RequestHandler {
5050
parsedUrl = new URL(requestUrl);
5151
} catch {
5252
return {
53-
responsePromise: Promise.reject(new OptimizelyError(UNSUPPORTED_PROTOCOL, requestUrl)),
53+
responsePromise: Promise.reject(new OptimizelyError(INVALID_REQUEST_URL, requestUrl)),
5454
abort: () => {},
5555
};
5656
}

0 commit comments

Comments
 (0)