Skip to content
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

422 (Unprocessable Entity) #56

Open
Devikrishna-J opened this issue Mar 1, 2022 · 0 comments
Open

422 (Unprocessable Entity) #56

Devikrishna-J opened this issue Mar 1, 2022 · 0 comments

Comments

@Devikrishna-J
Copy link

I'm new to Angular Js.
Below is a simple bank application, user can register,login the application. After successful login user can deposit ,withdraw cash and view his transaction history.
Register and Login is working. Deposit not working showing below error
Showing server error in browser as POST http://localhost:3000/deposit 422 (Unprocessable Entity)

** data.services.ts file**

const options={
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
}
//deposit API
deposit(acno:any,pswd:any,amnt:any){
const data={
acno,
pswd,
amnt
}

//deposit api
return this.http.post("http://localhost:3000/deposit",data,this.getOption())

}

//get options in httpheaders
getOption(){
const token = JSON.parse(localStorage.getItem("token")||'')

let headers = new HttpHeaders({ 'Content-Type': 'application/json' })
if(token){
    headers = headers.append('x-access-token',token)
    options.headers = headers
}
return options

}

deposit components.ts file

deposit(){

var acno=this.depositForm.value.acno
var pswd=this.depositForm.value.pswd
var amnt=this.depositForm.value.amnt


if(this.depositForm.valid){
  var result= this.ds.deposit(acno,pswd,amnt)
  .subscribe((result:any)=>{
      if(result){
        alert(result.message);
      }
  },
      (result)=>{
        alert(result.message)
      }
  )
  
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant