Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:27:07+00:00 2026-06-09T12:27:07+00:00

I created a function which checks parameters and decide to run the rest of

  • 0

I created a function which checks parameters and decide to run the rest of the code. I looks like:

def assert_something(a):
    if a>3:
        exit(0)

I try to use this something like:

class SomeHandler(webapp2.RequestHandler):
    def get(self,parameter):
        #check and if something wrong then quit
        assert_something(parameter)

        #otherwise do other things

the problem is exit() function always creates a response with 500 code.

How can modify this code so that I can exit from this request with 200 code for instance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:27:09+00:00Added an answer on June 9, 2026 at 12:27 pm

    The problem is that since you are using a framework a lot of things happens under the hood, for example after one of your handlers returns the headers and other information is sent to the browser. But when you exit you interrupt the normal flow hence the internal Server Error.

    What you could do is to have a decorator that asserts that the parameter is valid. Note that still you should provide the user with something useful in case the parameter is invalid.

    The decorator could be something like this:

    from functools import wraps
    
    def assert_something(f):
      @wraps(f)
      def wrapper(*args, **kwds):
        if args[1] > 3: #args[0] is self, args[1] is parameter. Better to use kwargs
          return None
        return f(*args, **kwds)
      return wrapper
    

    And then use it as:

    @assert_something
    def get(self, parameter):
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an utility function which I include in almost all Javascript code
I already managed to create function which checks if user is using a trial/demo
Ive created a function which returns all the obserables items in my html page.
I created a function which loads a very basic map file of the form:
I have created a function which gets an encoded string (possibly UTF-16 not sure)
I have created a JS function which executes fine when it's included an the
Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I have created a add input field function which is working fine. I would
I created webservice which contain Add function as 'webmethod' when we want to deploy
I created a sample webservice which contain default 'HelloWorld' function as 'webmethod' when tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.