Skip to content

Instantly share code, notes, and snippets.

@AhsanNissar
Created January 10, 2019 12:17
Show Gist options
  • Save AhsanNissar/420a0ad2f94ce15aefbd7d4240d15d7d to your computer and use it in GitHub Desktop.
Save AhsanNissar/420a0ad2f94ce15aefbd7d4240d15d7d to your computer and use it in GitHub Desktop.
GetSchoolStudents(schoolName: string): Observable<ListResultDtoOfStudentDto> {
let url_ = this.baseUrl + "/api/services/app/Student/GetSchoolStudents?";
if (schoolName === undefined || schoolName === null)
throw new Error("The parameter 'schoolName' must be defined and cannot be null.");
else
url_ += "schoolName=" + encodeURIComponent("" + schoolName);
url_ = url_.replace(/[?&]$/, "");
let options_: any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Content-Type": "application/json",
"Accept": "application/json"
})
};
return this.http.request("get", url_, options_).flatMap((response_: any) => {
return this.processGetSchoolAllStudents(response_);
}).catch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processGetSchoolAllStudents(<any>response_);
} catch (e) {
return <Observable<ListResultDtoOfStudentDto>><any>Observable.throw(e);
}
} else
return <Observable<ListResultDtoOfStudentDto>><any>Observable.throw(response_);
});
}
protected processGetSchoolAllStudents(response: HttpResponseBase): Observable<ListResultDtoOfStudentDto> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse ? response.body :
(<any>response).error instanceof Blob ? (<any>response).error : undefined;
let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); } };
if (status === 200) {
return blobToText(responseBlob).flatMap(_responseText => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 ? ListResultDtoOfStudentDto.fromJS(resultData200) : new ListResultDtoOfStudentDto();
return Observable.of(result200);
});
} else if (status === 401) {
return blobToText(responseBlob).flatMap(_responseText => {
return throwException("A server error occurred.", status, _responseText, _headers);
});
} else if (status === 403) {
return blobToText(responseBlob).flatMap(_responseText => {
return throwException("A server error occurred.", status, _responseText, _headers);
});
} else if (status !== 200 && status !== 204) {
return blobToText(responseBlob).flatMap(_responseText => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Observable.of<ListResultDtoOfStudentDto>(<any>null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment