Rayrun
← Back to Discord Forum

how to write better

const postConfirmResetPassword = page.waitForResponse( //v12/users/passwords/confirm_reset$/, { status: 422,
fixture: 'rest/users/passwords/confirm_reset_password/bad_token.json', } ); status code error

This thread is trying to answer question "What are some tips for writing better code when dealing with HTTP codes?"

4 replies

could you may store them inside ah json and import them ? should be an options since they are all strings. you should enable "resolveJsonModule": true, in your compilerOptions of tsconfig for this

Another tip, depending on how often you use certain HTTP codes, I always find I am asking what was this code mean. You can add a type or enum to hold all the HTTP codes. then your code would be read without the code.

status: HttpStatusCode. UprocessableEntity which evaluates to 422

Going to the next level you can then group these codes to types that are for successful. retryable, server error, client error to make your code easier to read. This is optional, but we find it helpful.

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].