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

Status 422 for http post in Angular 6 #216

Open

Description

@angelitoTalens

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);

Activity

  1. chorsnell commented on Oct 10, 2018

    @chorsnell

    @angelitoTalens did you get to the bottom of this?

  2. hungerregnuh commented on Nov 29, 2018

    @hungerregnuh

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

  3. angelitoTalens commented on Nov 30, 2018

    @angelitoTalens
    Author

    @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})
    ],

  4. hungerregnuh commented on Nov 30, 2018

    @hungerregnuh

    @angelitoTalens

    could you try this instead?

    createDb() {
      const login = [
        {
          id: 1,
          email: 'first.last@gmail.com',
          password: 'pwd'
        }
      ];
    
  5. angelitoTalens commented on Dec 4, 2018

    @angelitoTalens
    Author

    @hungerregnuh

    your suggestion worked for me.

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

  6. keerthi42 commented on Sep 7, 2019

    @keerthi42

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions