@warp-drive/legacy 5.7.0-alpha.1 → 5.7.0-alpha.3
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiError } from "@warp-drive/core/types/spec/error";
|
|
2
2
|
export interface AdapterRequestError<T extends string = string> extends Error {
|
|
3
3
|
isAdapterError: true;
|
|
4
4
|
code: T;
|
|
5
|
-
errors:
|
|
5
|
+
errors: ApiError[];
|
|
6
6
|
}
|
|
7
7
|
export interface AdapterRequestErrorConstructor<Instance extends AdapterRequestError = AdapterRequestError> {
|
|
8
8
|
new (errors?: unknown[], message?: string): Instance;
|
package/dist/adapter/error.js
CHANGED
|
@@ -4,6 +4,72 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
<blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
|
|
11
|
+
<p>
|
|
12
|
+
⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
|
|
13
|
+
If starting a new app or thinking of implementing a new adapter, consider writing a
|
|
14
|
+
<a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
|
|
15
|
+
</p>
|
|
16
|
+
</blockquote>
|
|
17
|
+
|
|
18
|
+
An `AdapterError` is used by an adapter to signal that an error occurred
|
|
19
|
+
during a request to an external API. It indicates a generic error, and
|
|
20
|
+
subclasses are used to indicate specific error states.
|
|
21
|
+
|
|
22
|
+
To create a custom error to signal a specific error state in communicating
|
|
23
|
+
with an external API, extend the `AdapterError`. For example, if the
|
|
24
|
+
external API exclusively used HTTP `503 Service Unavailable` to indicate
|
|
25
|
+
it was closed for maintenance:
|
|
26
|
+
|
|
27
|
+
```js [app/adapters/maintenance-error.js]
|
|
28
|
+
import AdapterError from '@ember-data/adapter/error';
|
|
29
|
+
|
|
30
|
+
export default AdapterError.extend({ message: "Down for maintenance." });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This error would then be returned by an adapter's `handleResponse` method:
|
|
34
|
+
|
|
35
|
+
```js [app/adapters/application.js]
|
|
36
|
+
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
37
|
+
import MaintenanceError from './maintenance-error';
|
|
38
|
+
|
|
39
|
+
export default class ApplicationAdapter extends JSONAPIAdapter {
|
|
40
|
+
handleResponse(status) {
|
|
41
|
+
if (503 === status) {
|
|
42
|
+
return new MaintenanceError();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return super.handleResponse(...arguments);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
And can then be detected in an application and used to send the user to an
|
|
51
|
+
`under-maintenance` route:
|
|
52
|
+
|
|
53
|
+
```js [app/routes/application.js]
|
|
54
|
+
import MaintenanceError from '../adapters/maintenance-error';
|
|
55
|
+
|
|
56
|
+
export default class ApplicationRoute extends Route {
|
|
57
|
+
actions: {
|
|
58
|
+
error(error, transition) {
|
|
59
|
+
if (error instanceof MaintenanceError) {
|
|
60
|
+
this.transitionTo('under-maintenance');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ...other error handling logic
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
@class AdapterError
|
|
71
|
+
@public
|
|
72
|
+
*/
|
|
7
73
|
function _AdapterError(errors, message = 'Adapter operation failed') {
|
|
8
74
|
this.isAdapterError = true;
|
|
9
75
|
const error = Error.call(this, message);
|
package/dist/adapter/rest.js
CHANGED
|
@@ -776,7 +776,7 @@ class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
|
776
776
|
if (this.isSuccess(status, headers, payload)) {
|
|
777
777
|
return payload;
|
|
778
778
|
} else if (this.isInvalid(status, headers, payload)) {
|
|
779
|
-
// @ts-expect-error needs cast to
|
|
779
|
+
// @ts-expect-error needs cast to ApiError
|
|
780
780
|
return new InvalidError(typeof payload === 'object' && 'errors' in payload ? payload.errors : undefined);
|
|
781
781
|
}
|
|
782
782
|
const errors = this.normalizeErrorResponse(status, headers, payload);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/legacy",
|
|
3
|
-
"version": "5.7.0-alpha.
|
|
3
|
+
"version": "5.7.0-alpha.3",
|
|
4
4
|
"description": "Decommissioned Packages for WarpDrive | Things your app might still want to maintain use of for a little longer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@warp-drive/core": "5.7.0-alpha.
|
|
36
|
-
"@warp-drive/utilities": "5.7.0-alpha.
|
|
35
|
+
"@warp-drive/core": "5.7.0-alpha.3",
|
|
36
|
+
"@warp-drive/utilities": "5.7.0-alpha.3"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@embroider/macros": "^1.16.12"
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
44
44
|
"@babel/preset-typescript": "^7.27.0",
|
|
45
45
|
"@types/jquery": "^3.5.32",
|
|
46
|
-
"@warp-drive/internal-config": "5.7.0-alpha.
|
|
47
|
-
"@warp-drive/core": "5.7.0-alpha.
|
|
48
|
-
"@warp-drive/utilities": "5.7.0-alpha.
|
|
46
|
+
"@warp-drive/internal-config": "5.7.0-alpha.3",
|
|
47
|
+
"@warp-drive/core": "5.7.0-alpha.3",
|
|
48
|
+
"@warp-drive/utilities": "5.7.0-alpha.3",
|
|
49
49
|
"ember-source": "~6.3.0",
|
|
50
50
|
"decorator-transforms": "^2.3.0",
|
|
51
51
|
"expect-type": "^1.2.1",
|