Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit b363e3b

Browse files
Gabriel Smoljárknalli
authored andcommitted
feat: throw TypeError for translationId
AngularJS 1.6 introduced a new behaviour that caused an exception on unhandled rejections of promises. If you were to pass undefined to to $translate the error message would simply be "Possibly unhandled rejection: undefined". With this change a TypeError is thrown instead so that you can easly find where the invalid translationId was passed from in the stack trace feat: throw TypeError for translationId AngularJS 1.6 introduced a new behaviour that caused an exception on unhandled rejections of promises. If you were to pass undefined to to $translate the error message would simply be "Possibly unhandled rejection: undefined". With this change a TypeError is thrown instead so that you can easly find where the invalid translationId was passed from in the stack trace (cherry picked from commit c4f5c24)
1 parent e01e5af commit b363e3b

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/service/translate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,8 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
11451145
// trim off any whitespace
11461146
if (translationId) {
11471147
translationId = trim.apply(translationId);
1148+
} else {
1149+
throw new TypeError('translationId must be a not empty string');
11481150
}
11491151

11501152
var promiseToWaitFor = (function () {

test/unit/service/translate.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ describe('pascalprecht.translate', function () {
256256
expect(value).toEqual(translationId);
257257
});
258258

259+
it('should throw if id is not a string or array of strings', function () {
260+
expect(function () { $translate(undefined); }).toThrowError(TypeError);
261+
});
262+
259263
it('should return translation id if translation is null', function () {
260264
var deferred = $q.defer(),
261265
promise = deferred.promise,

0 commit comments

Comments
 (0)