Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Status 422 for http post in Angular 6 #216

Open
angelitoTalens opened this issue Sep 12, 2018 · 6 comments
Open

Status 422 for http post in Angular 6 #216

angelitoTalens opened this issue Sep 12, 2018 · 6 comments

Comments

@angelitoTalens
Copy link

angelitoTalens commented Sep 12, 2018

Encountered this error:
body:error:"Collection 'login' id type is non-numeric or unknown. Can only generate numeric ids."
status:422
statusText:"Unprocessable Entity"

when doing a post using:

  • Angular 6
  • angular-in-memory-web-api 0.6.1

const options = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
const body = JSON.stringify({email: email, password: password});
return this.http.post<boolean>(apiUrl, body, options);

@chorsnell
Copy link

@angelitoTalens did you get to the bottom of this?

@hungerregnuh
Copy link

This is working fine for me in v7, how did you setup your in memory data service?

@angelitoTalens
Copy link
Author

angelitoTalens commented Nov 30, 2018

@hungerregnuh

mock-api.service.ts

export class MockApiService implements InMemoryDbService {
createDb() {
let login:{email:string, password:string}[] = [{
email:'first.last@gmail.com',
password:'pwd'
}];

return {
login
};
}
}

In app.module.ts

imports: [
...
environment.production ?
[] : HttpClientInMemoryWebApiModule.forRoot(MockApiService, {post204: false, post409: true, dataEncapsulation: false})
],

@hungerregnuh
Copy link

@angelitoTalens

could you try this instead?

createDb() {
  const login = [
    {
      id: 1,
      email: 'first.last@gmail.com',
      password: 'pwd'
    }
  ];

@angelitoTalens
Copy link
Author

@hungerregnuh

your suggestion worked for me.

let userCredentials = {email: email, password: password};
return this.http.post<boolean>(apiUrl, userCredentials, options)

@keerthi42
Copy link

Encountered this error:
body:error:"Collection 'inputparams' id type is non-numeric or unknown. Can only generate numeric ids."
status:422
statusText:"Unprocessable Entity"

when doing a post using:

Angular 7
angular-in-memory-web-api
const url = ${this.apiUrl};
return this.http.post(url, JSON.stringify( param), httpOptions).pipe(map(this.serviceHelper.extractData))
.pipe(catchError(this.serviceHelper.handleError));](url)

here is what the "param" consists of
common: OEGenericInputParameter;
fleet: OEInputParameterWideBody[];
optional: OEInputParameterOptions;

User gives details in the form
all the details are clubbed and made as param model
createDB(){
const inputparamsfun = () =>{
what to be given here?
}
}

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

No branches or pull requests

4 participants