Skip to content

Commit e7656b8

Browse files
arturovtthePunderWoman
authored andcommitted
refactor(core): drop rxResource error messages (angular#61565)
Drops `rxResource` error messages in production and replaces with error codes. PR Close angular#61565
1 parent 6218571 commit e7656b8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

goldens/public-api/core/errors.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export const enum RuntimeErrorCode {
122122
// (undocumented)
123123
MULTIPLE_PLATFORMS = 400,
124124
// (undocumented)
125+
MUST_PROVIDE_STREAM_OPTION = 990,
126+
// (undocumented)
125127
NO_BINDING_TARGET = 315,
126128
// (undocumented)
127129
NO_COMPONENT_FACTORY_FOUND = 917,
@@ -154,6 +156,8 @@ export const enum RuntimeErrorCode {
154156
// (undocumented)
155157
REQUIRED_QUERY_NO_VALUE = -951,
156158
// (undocumented)
159+
RESOURCE_COMPLETED_BEFORE_PRODUCING_VALUE = 991,
160+
// (undocumented)
157161
RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 980,
158162
// (undocumented)
159163
RUNTIME_DEPS_ORPHAN_COMPONENT = 981,

packages/core/rxjs-interop/src/rx_resource.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
Signal,
1515
signal,
1616
BaseResourceOptions,
17+
ɵRuntimeError,
18+
ɵRuntimeErrorCode,
1719
} from '../../src/core';
1820
import {Observable, Subscription} from 'rxjs';
1921

@@ -72,15 +74,23 @@ export function rxResource<T, R>(opts: RxResourceOptions<T, R>): ResourceRef<T |
7274
// TODO(alxhub): remove after g3 updated to rename loader -> stream
7375
const streamFn = opts.stream ?? (opts as {loader?: RxResourceOptions<T, R>['stream']}).loader;
7476
if (streamFn === undefined) {
75-
throw new Error(`Must provide \`stream\` option.`);
77+
throw new ɵRuntimeError(
78+
ɵRuntimeErrorCode.MUST_PROVIDE_STREAM_OPTION,
79+
ngDevMode && `Must provide \`stream\` option.`,
80+
);
7681
}
7782

7883
sub = streamFn(params).subscribe({
7984
next: (value) => send({value}),
8085
error: (error) => send({error}),
8186
complete: () => {
8287
if (resolve) {
83-
send({error: new Error('Resource completed before producing a value')});
88+
send({
89+
error: new ɵRuntimeError(
90+
ɵRuntimeErrorCode.RESOURCE_COMPLETED_BEFORE_PRODUCING_VALUE,
91+
ngDevMode && 'Resource completed before producing a value',
92+
),
93+
});
8494
}
8595
params.abortSignal.removeEventListener('abort', onAbort);
8696
},

packages/core/src/errors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ export const enum RuntimeErrorCode {
143143
RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 980,
144144
RUNTIME_DEPS_ORPHAN_COMPONENT = 981,
145145

146+
// Resource errors
147+
MUST_PROVIDE_STREAM_OPTION = 990,
148+
RESOURCE_COMPLETED_BEFORE_PRODUCING_VALUE = 991,
149+
146150
// Upper bounds for core runtime errors is 999
147151
}
148152

0 commit comments

Comments
 (0)