@schmock/angular 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +23 -4
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -35121,6 +35121,24 @@ var CACHE_OPTIONS = new InjectionToken(ngDevMode ? "HTTP_TRANSFER_STATE_CACHE_OP
35121
35121
 
35122
35122
  // src/index.ts
35123
35123
  var import_rxjs3 = __toESM(require_cjs(), 1);
35124
+ var HTTP_METHODS = [
35125
+ "GET",
35126
+ "POST",
35127
+ "PUT",
35128
+ "DELETE",
35129
+ "PATCH",
35130
+ "HEAD",
35131
+ "OPTIONS"
35132
+ ];
35133
+ function isHttpMethod(method) {
35134
+ return HTTP_METHODS.includes(method);
35135
+ }
35136
+ function toHttpMethod(method) {
35137
+ if (isHttpMethod(method)) {
35138
+ return method;
35139
+ }
35140
+ return "GET";
35141
+ }
35124
35142
  function extractQueryParams(url) {
35125
35143
  const queryStart = url.indexOf("?");
35126
35144
  if (queryStart === -1)
@@ -35163,7 +35181,7 @@ function createSchmockInterceptor(mock, options = {}) {
35163
35181
  const path = extractPath(req.url);
35164
35182
  const query = extractQueryParams(req.url);
35165
35183
  let requestData = {
35166
- method: req.method,
35184
+ method: toHttpMethod(req.method),
35167
35185
  path,
35168
35186
  headers: headersToObject(req),
35169
35187
  body: req.body,
@@ -35174,7 +35192,7 @@ function createSchmockInterceptor(mock, options = {}) {
35174
35192
  requestData = {
35175
35193
  ...requestData,
35176
35194
  ...transformed,
35177
- method: transformed.method || requestData.method
35195
+ method: toHttpMethod(transformed.method ?? req.method)
35178
35196
  };
35179
35197
  }
35180
35198
  return new import_rxjs3.Observable((observer) => {
@@ -35210,11 +35228,12 @@ function createSchmockInterceptor(mock, options = {}) {
35210
35228
  }).catch((error) => {
35211
35229
  let errorBody;
35212
35230
  if (errorFormatter) {
35213
- errorBody = errorFormatter(error, req);
35231
+ errorBody = errorFormatter(error instanceof Error ? error : new Error(String(error)), req);
35214
35232
  } else {
35233
+ const errorWithCode = error;
35215
35234
  errorBody = {
35216
35235
  error: error instanceof Error ? error.message : "Internal Server Error",
35217
- code: error.code || "INTERNAL_ERROR"
35236
+ code: errorWithCode.code ?? "INTERNAL_ERROR"
35218
35237
  };
35219
35238
  }
35220
35239
  observer.error(new HttpErrorResponse({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schmock/angular",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Angular HTTP interceptor adapter for Schmock",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "lint:fix": "biome check --write src"
21
21
  },
22
22
  "dependencies": {
23
- "@schmock/core": "workspace:*",
23
+ "@schmock/core": "^1.0.0",
24
24
  "rxjs": "^7.8.1"
25
25
  },
26
26
  "peerDependencies": {