-
-
Notifications
You must be signed in to change notification settings - Fork 539
Feature/angular #944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/angular #944
Conversation
Codecov Report
@@ Coverage Diff @@
## master #944 +/- ##
==========================================
- Coverage 86.76% 86.66% -0.10%
==========================================
Files 107 107
Lines 1685 1695 +10
Branches 350 352 +2
==========================================
+ Hits 1462 1469 +7
- Misses 223 226 +3
Continue to review full report at Codecov.
|
The request method now looks like this (i added comments to make it clear, but those are not in the output): /**
* Request method
* @param config The OpenAPI configuration object
* @param http The Angular HTTP client
* @param options The request options from the service
* @returns Observable<T>
* @throws ApiError
*/
export const request = <T>(config: OpenAPIConfig, http: HttpClient, options: ApiRequestOptions): Observable<T> => {
const url = getUrl(config, options);
const formData = getFormData(options);
const body = getRequestBody(options);
// getHeaders has been converted to observable
return getHeaders(config, options).pipe(
mergeMap( headers => {
// When have received the headers, then we can send the request
return sendRequest<T>(config, options, http, url, formData, body, headers);
}),
// We map the response (if successful)
map(response => {
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);
return {
url,
ok: response.ok,
status: response.status,
statusText: response.statusText,
body: responseHeader ?? responseBody,
} as ApiResult;
}),
// If there is a HTTP error, then we capture it
// If this is a error without a status (network error) we just throw it
// Otherwise we convert it to a result object for further processing (error code could be associated with a custom error message)
catchError((error: HttpErrorResponse) => {
if (!error.status) {
return throwError(() => error);
}
return of({
url,
ok: error.ok,
status: error.status,
statusText: error.statusText,
body: error.statusText,
} as ApiResult);
}),
// We catch the ApiResult object and check it for errors
// If catchErrorCodes does not find anything then we return the result
map(result => {
catchErrorCodes(options, result);
return result.body as T;
}),
// If catchErrorCodes did throw an error, then we just throw it to the subscriber
catchError((error: ApiError) => {
return throwError(() => error);
}),
);
}; |
The client passes the test cases and you can still do things like |
note to self: need to switch to |
- Fixed capture of error body in Angular
Creating the PR for the Angular client (WIP) needs some changes on the error handling.
See #935 (comment) for some discussions on the work so far