Sha256: f0cd6d7116211124b19428d2a8425227d3614894c12d6518ab377836ad2fc063
Contents?: true
Size: 1.17 KB
Versions: 4
Compression:
Stored size: 1.17 KB
Contents
import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Response } from '@angular/http'; import 'rxjs/add/observable/of'; import 'rxjs/add/observable/throw'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import { HttpService } from '../services/http/http.service'; export interface IAccount { name: string email: string password: string password_confirmation: string } @Injectable() export class RegistrationService { constructor(private http: HttpService) {} registerAccount(acct: IAccount) { return this.http.post('/user', acct) .map(this.extractData) .catch(this.handleError) } private extractData (res) { return res.json() } private handleError(err: Response) { console.log(err) let errors: any; try { errors = err.json(); errors['name'] = errors['name'] || [] errors['email'] = errors['email'] || [] errors['password'] = errors['password'] || [] errors['password_confirmation'] = errors['password_confirmation'] || [] } catch (e) { errors = [err.text] } return Observable.throw(errors) } }
Version data entries
4 entries across 4 versions & 1 rubygems